]>
Commit | Line | Data |
---|---|---|
1c4293cb VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/propgrid/editors.cpp | |
3 | // Purpose: wxPropertyGrid editors | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2007-04-14 | |
ea5af9c5 | 7 | // RCS-ID: $Id$ |
1c4293cb VZ |
8 | // Copyright: (c) Jaakko Salli |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
f4bc1aa2 JS |
19 | #if wxUSE_PROPGRID |
20 | ||
1c4293cb VZ |
21 | #ifndef WX_PRECOMP |
22 | #include "wx/defs.h" | |
23 | #include "wx/object.h" | |
24 | #include "wx/hash.h" | |
25 | #include "wx/string.h" | |
26 | #include "wx/log.h" | |
27 | #include "wx/event.h" | |
28 | #include "wx/window.h" | |
29 | #include "wx/panel.h" | |
30 | #include "wx/dc.h" | |
31 | #include "wx/dcclient.h" | |
32 | #include "wx/dcmemory.h" | |
33 | #include "wx/button.h" | |
34 | #include "wx/pen.h" | |
35 | #include "wx/brush.h" | |
36 | #include "wx/cursor.h" | |
37 | #include "wx/dialog.h" | |
38 | #include "wx/settings.h" | |
39 | #include "wx/msgdlg.h" | |
40 | #include "wx/choice.h" | |
41 | #include "wx/stattext.h" | |
42 | #include "wx/scrolwin.h" | |
43 | #include "wx/dirdlg.h" | |
1c4293cb VZ |
44 | #include "wx/sizer.h" |
45 | #include "wx/textdlg.h" | |
46 | #include "wx/filedlg.h" | |
47 | #include "wx/statusbr.h" | |
48 | #include "wx/intl.h" | |
49 | #include "wx/frame.h" | |
50 | #endif | |
51 | ||
52 | ||
53 | #include "wx/timer.h" | |
54 | #include "wx/dcbuffer.h" | |
55 | #include "wx/bmpbuttn.h" | |
56 | ||
57 | ||
58 | // This define is necessary to prevent macro clearing | |
59 | #define __wxPG_SOURCE_FILE__ | |
60 | ||
3b211af1 SC |
61 | #include "wx/propgrid/propgrid.h" |
62 | #include "wx/propgrid/editors.h" | |
63 | #include "wx/propgrid/props.h" | |
1c4293cb VZ |
64 | |
65 | #if wxPG_USE_RENDERER_NATIVE | |
3b211af1 | 66 | #include "wx/renderer.h" |
1c4293cb VZ |
67 | #endif |
68 | ||
69 | // How many pixels between textctrl and button | |
70 | #ifdef __WXMAC__ | |
13ab7561 | 71 | #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 4 |
1c4293cb VZ |
72 | #else |
73 | #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2 | |
74 | #endif | |
75 | ||
76 | #define wxPG_BUTTON_SIZEDEC 0 | |
77 | ||
3b211af1 | 78 | #include "wx/odcombo.h" |
1c4293cb VZ |
79 | |
80 | #ifdef __WXMSW__ | |
3b211af1 | 81 | #include "wx/msw/private.h" |
1c4293cb VZ |
82 | #endif |
83 | ||
84 | // ----------------------------------------------------------------------- | |
85 | ||
86 | #if defined(__WXMSW__) | |
87 | // tested | |
1c4293cb VZ |
88 | #define wxPG_NAT_BUTTON_BORDER_ANY 1 |
89 | #define wxPG_NAT_BUTTON_BORDER_X 1 | |
90 | #define wxPG_NAT_BUTTON_BORDER_Y 1 | |
91 | ||
92 | #define wxPG_CHECKMARK_XADJ 1 | |
93 | #define wxPG_CHECKMARK_YADJ (-1) | |
94 | #define wxPG_CHECKMARK_WADJ 0 | |
95 | #define wxPG_CHECKMARK_HADJ 0 | |
96 | #define wxPG_CHECKMARK_DEFLATE 0 | |
97 | ||
98 | #define wxPG_TEXTCTRLYADJUST (m_spacingy+0) | |
99 | ||
100 | #elif defined(__WXGTK__) | |
101 | // tested | |
102 | #define wxPG_CHECKMARK_XADJ 0 | |
103 | #define wxPG_CHECKMARK_YADJ 0 | |
104 | #define wxPG_CHECKMARK_WADJ (-1) | |
105 | #define wxPG_CHECKMARK_HADJ (-1) | |
106 | #define wxPG_CHECKMARK_DEFLATE 3 | |
107 | ||
1c4293cb VZ |
108 | #define wxPG_NAT_BUTTON_BORDER_ANY 1 |
109 | #define wxPG_NAT_BUTTON_BORDER_X 1 | |
110 | #define wxPG_NAT_BUTTON_BORDER_Y 1 | |
111 | ||
112 | #define wxPG_TEXTCTRLYADJUST 0 | |
113 | ||
114 | #elif defined(__WXMAC__) | |
115 | // *not* tested | |
116 | #define wxPG_CHECKMARK_XADJ 0 | |
117 | #define wxPG_CHECKMARK_YADJ 0 | |
118 | #define wxPG_CHECKMARK_WADJ 0 | |
119 | #define wxPG_CHECKMARK_HADJ 0 | |
120 | #define wxPG_CHECKMARK_DEFLATE 0 | |
121 | ||
1c4293cb VZ |
122 | #define wxPG_NAT_BUTTON_BORDER_ANY 0 |
123 | #define wxPG_NAT_BUTTON_BORDER_X 0 | |
124 | #define wxPG_NAT_BUTTON_BORDER_Y 0 | |
125 | ||
012b4a07 | 126 | #define wxPG_TEXTCTRLYADJUST 0 |
1c4293cb VZ |
127 | |
128 | #else | |
129 | // defaults | |
130 | #define wxPG_CHECKMARK_XADJ 0 | |
131 | #define wxPG_CHECKMARK_YADJ 0 | |
132 | #define wxPG_CHECKMARK_WADJ 0 | |
133 | #define wxPG_CHECKMARK_HADJ 0 | |
134 | #define wxPG_CHECKMARK_DEFLATE 0 | |
135 | ||
1c4293cb VZ |
136 | #define wxPG_NAT_BUTTON_BORDER_ANY 0 |
137 | #define wxPG_NAT_BUTTON_BORDER_X 0 | |
138 | #define wxPG_NAT_BUTTON_BORDER_Y 0 | |
139 | ||
140 | #define wxPG_TEXTCTRLYADJUST 0 | |
141 | ||
142 | #endif | |
143 | ||
1c4293cb | 144 | // for odcombo |
53ba104e | 145 | #ifdef __WXMAC__ |
13ab7561 RR |
146 | #define wxPG_CHOICEXADJUST -3 // required because wxComboCtrl reserves 3pixels for wxTextCtrl's focus ring |
147 | #define wxPG_CHOICEYADJUST -3 | |
53ba104e | 148 | #else |
1c4293cb VZ |
149 | #define wxPG_CHOICEXADJUST 0 |
150 | #define wxPG_CHOICEYADJUST 0 | |
53ba104e | 151 | #endif |
1c4293cb VZ |
152 | |
153 | #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth | |
154 | ||
155 | // Milliseconds to wait for two mouse-ups after focus inorder | |
156 | // to trigger a double-click. | |
157 | #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500 | |
158 | ||
159 | // ----------------------------------------------------------------------- | |
160 | // wxPGEditor | |
161 | // ----------------------------------------------------------------------- | |
162 | ||
163 | IMPLEMENT_ABSTRACT_CLASS(wxPGEditor, wxObject) | |
164 | ||
165 | ||
166 | wxPGEditor::~wxPGEditor() | |
167 | { | |
168 | } | |
169 | ||
5a45dd6f JS |
170 | wxString wxPGEditor::GetName() const |
171 | { | |
172 | return GetClassInfo()->GetClassName(); | |
173 | } | |
174 | ||
1c4293cb VZ |
175 | void wxPGEditor::DrawValue( wxDC& dc, const wxRect& rect, wxPGProperty* property, const wxString& text ) const |
176 | { | |
177 | if ( !property->IsValueUnspecified() ) | |
178 | dc.DrawText( text, rect.x+wxPG_XBEFORETEXT, rect.y ); | |
179 | } | |
180 | ||
181 | bool wxPGEditor::GetValueFromControl( wxVariant&, wxPGProperty*, wxWindow* ) const | |
182 | { | |
183 | return false; | |
184 | } | |
185 | ||
186 | void wxPGEditor::SetControlStringValue( wxPGProperty* WXUNUSED(property), wxWindow*, const wxString& ) const | |
187 | { | |
188 | } | |
189 | ||
190 | ||
191 | void wxPGEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow*, int ) const | |
192 | { | |
193 | } | |
194 | ||
195 | ||
196 | int wxPGEditor::InsertItem( wxWindow*, const wxString&, int ) const | |
197 | { | |
198 | return -1; | |
199 | } | |
200 | ||
201 | ||
202 | void wxPGEditor::DeleteItem( wxWindow*, int ) const | |
203 | { | |
204 | return; | |
205 | } | |
206 | ||
207 | ||
208 | void wxPGEditor::OnFocus( wxPGProperty*, wxWindow* ) const | |
209 | { | |
210 | } | |
211 | ||
212 | ||
213 | bool wxPGEditor::CanContainCustomImage() const | |
214 | { | |
215 | return false; | |
216 | } | |
217 | ||
1c4293cb VZ |
218 | // ----------------------------------------------------------------------- |
219 | // wxPGTextCtrlEditor | |
220 | // ----------------------------------------------------------------------- | |
221 | ||
52cefafe | 222 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl,wxPGTextCtrlEditor,wxPGEditor) |
1c4293cb VZ |
223 | |
224 | ||
225 | wxPGWindowList wxPGTextCtrlEditor::CreateControls( wxPropertyGrid* propGrid, | |
226 | wxPGProperty* property, | |
227 | const wxPoint& pos, | |
228 | const wxSize& sz ) const | |
229 | { | |
230 | wxString text; | |
231 | ||
232 | // | |
233 | // If has children, and limited editing is specified, then don't create. | |
234 | if ( (property->GetFlags() & wxPG_PROP_NOEDITOR) && | |
235 | property->GetChildCount() ) | |
236 | return (wxWindow*) NULL; | |
237 | ||
238 | if ( !property->IsValueUnspecified() ) | |
1425eca5 JS |
239 | text = property->GetValueAsString(property->HasFlag(wxPG_PROP_READONLY) ? |
240 | 0 : wxPG_EDITABLE_VALUE); | |
1c4293cb VZ |
241 | |
242 | int flags = 0; | |
243 | if ( (property->GetFlags() & wxPG_PROP_PASSWORD) && | |
244 | property->IsKindOf(CLASSINFO(wxStringProperty)) ) | |
245 | flags |= wxTE_PASSWORD; | |
246 | ||
247 | wxWindow* wnd = propGrid->GenerateEditorTextCtrl(pos,sz,text,(wxWindow*)NULL,flags, | |
248 | property->GetMaxLength()); | |
249 | ||
250 | return wnd; | |
251 | } | |
252 | ||
253 | #if 0 | |
254 | void wxPGTextCtrlEditor::DrawValue( wxDC& dc, wxPGProperty* property, const wxRect& rect ) const | |
255 | { | |
256 | if ( !property->IsValueUnspecified() ) | |
257 | { | |
258 | wxString drawStr = property->GetDisplayedString(); | |
259 | ||
260 | // Code below should no longer be needed, as the obfuscation | |
261 | // is now done in GetValueAsString. | |
262 | /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) && | |
263 | property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) ) | |
264 | { | |
265 | size_t a = drawStr.length(); | |
266 | drawStr.Empty(); | |
267 | drawStr.Append(wxS('*'),a); | |
268 | }*/ | |
269 | dc.DrawText( drawStr, rect.x+wxPG_XBEFORETEXT, rect.y ); | |
270 | } | |
271 | } | |
272 | #endif | |
273 | ||
274 | void wxPGTextCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const | |
275 | { | |
d27f4c7b RR |
276 | wxTextCtrl* tc = wxDynamicCast(ctrl, wxTextCtrl); |
277 | if (!tc) return; | |
1c4293cb VZ |
278 | |
279 | wxString s; | |
280 | ||
281 | if ( tc->HasFlag(wxTE_PASSWORD) ) | |
282 | s = property->GetValueAsString(wxPG_FULL_VALUE); | |
283 | else | |
284 | s = property->GetDisplayedString(); | |
285 | ||
f521bae6 JS |
286 | tc->SetValue(s); |
287 | ||
a6353fe8 JS |
288 | // |
289 | // Fix indentation, just in case (change in font boldness is one good | |
290 | // reason). | |
f521bae6 | 291 | #if defined(__WXMSW__) && !defined(__WXWINCE__) |
a6353fe8 JS |
292 | ::SendMessage(GetHwndOf(tc), |
293 | EM_SETMARGINS, | |
294 | EC_LEFTMARGIN | EC_RIGHTMARGIN, | |
295 | MAKELONG(0, 0)); | |
f521bae6 | 296 | #endif |
f521bae6 | 297 | } |
1c4293cb VZ |
298 | |
299 | // Provided so that, for example, ComboBox editor can use the same code | |
300 | // (multiple inheritance would get way too messy). | |
301 | bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid* propGrid, | |
302 | wxPGProperty* WXUNUSED(property), | |
303 | wxWindow* ctrl, | |
304 | wxEvent& event ) | |
305 | { | |
306 | if ( !ctrl ) | |
307 | return false; | |
308 | ||
309 | if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER ) | |
310 | { | |
311 | if ( propGrid->IsEditorsValueModified() ) | |
312 | { | |
313 | return true; | |
314 | } | |
315 | } | |
316 | else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED ) | |
317 | { | |
318 | // | |
319 | // Pass this event outside wxPropertyGrid so that, | |
320 | // if necessary, program can tell when user is editing | |
321 | // a textctrl. | |
322 | // FIXME: Is it safe to change event id in the middle of event | |
323 | // processing (seems to work, but...)? | |
324 | event.Skip(); | |
325 | event.SetId(propGrid->GetId()); | |
326 | ||
327 | propGrid->EditorsValueWasModified(); | |
328 | } | |
329 | return false; | |
330 | } | |
331 | ||
332 | ||
333 | bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid* propGrid, | |
334 | wxPGProperty* property, | |
335 | wxWindow* ctrl, | |
336 | wxEvent& event ) const | |
337 | { | |
338 | return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid,property,ctrl,event); | |
339 | } | |
340 | ||
341 | ||
342 | bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) | |
343 | { | |
344 | wxTextCtrl* tc = wxStaticCast(ctrl, wxTextCtrl); | |
345 | wxString textVal = tc->GetValue(); | |
346 | ||
347 | if ( property->UsesAutoUnspecified() && !textVal.length() ) | |
348 | { | |
349 | variant.MakeNull(); | |
350 | return true; | |
351 | } | |
352 | ||
353 | bool res = property->StringToValue(variant, textVal, wxPG_EDITABLE_VALUE); | |
354 | ||
355 | // Changing unspecified always causes event (returning | |
356 | // true here should be enough to trigger it). | |
357 | // TODO: Move to propgrid.cpp | |
358 | if ( !res && variant.IsNull() ) | |
359 | res = true; | |
360 | ||
361 | return res; | |
362 | } | |
363 | ||
364 | ||
365 | bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const | |
366 | { | |
367 | return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant, property, ctrl); | |
368 | } | |
369 | ||
370 | ||
371 | void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty* property, wxWindow* ctrl ) const | |
372 | { | |
373 | wxTextCtrl* tc = wxStaticCast(ctrl, wxTextCtrl); | |
374 | ||
375 | wxPropertyGrid* pg = property->GetGrid(); | |
376 | wxASSERT(pg); // Really, property grid should exist if editor does | |
377 | if ( pg ) | |
378 | tc->SetValue(wxEmptyString); | |
379 | } | |
380 | ||
381 | ||
382 | void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty* property, wxWindow* ctrl, const wxString& txt ) const | |
383 | { | |
384 | wxTextCtrl* tc = wxStaticCast(ctrl, wxTextCtrl); | |
385 | ||
386 | wxPropertyGrid* pg = property->GetGrid(); | |
387 | wxASSERT(pg); // Really, property grid should exist if editor does | |
388 | if ( pg ) | |
389 | tc->SetValue(txt); | |
390 | } | |
391 | ||
392 | ||
393 | void wxPGTextCtrlEditor::OnFocus( wxPGProperty*, wxWindow* wnd ) const | |
394 | { | |
395 | wxTextCtrl* tc = wxStaticCast(wnd, wxTextCtrl); | |
396 | ||
397 | tc->SetSelection(-1,-1); | |
398 | } | |
399 | ||
400 | ||
401 | wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { } | |
402 | ||
403 | ||
404 | // ----------------------------------------------------------------------- | |
405 | // wxPGChoiceEditor | |
406 | // ----------------------------------------------------------------------- | |
407 | ||
408 | ||
52cefafe | 409 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice,wxPGChoiceEditor,wxPGEditor) |
1c4293cb VZ |
410 | |
411 | ||
412 | // This is a special enhanced double-click processor class. | |
413 | // In essence, it allows for double-clicks for which the | |
414 | // first click "created" the control. | |
415 | class wxPGDoubleClickProcessor : public wxEvtHandler | |
416 | { | |
417 | public: | |
418 | ||
419 | wxPGDoubleClickProcessor( wxOwnerDrawnComboBox* combo, wxPGProperty* property ) | |
420 | : wxEvtHandler() | |
421 | { | |
422 | m_timeLastMouseUp = 0; | |
423 | m_combo = combo; | |
424 | m_property = property; | |
425 | m_downReceived = false; | |
426 | } | |
427 | ||
428 | protected: | |
429 | ||
430 | void OnMouseEvent( wxMouseEvent& event ) | |
431 | { | |
432 | wxLongLong t = ::wxGetLocalTimeMillis(); | |
433 | int evtType = event.GetEventType(); | |
434 | ||
435 | if ( m_property->HasFlag(wxPG_PROP_USE_DCC) && | |
436 | m_property->IsKindOf(CLASSINFO(wxBoolProperty)) && | |
437 | !m_combo->IsPopupShown() ) | |
438 | { | |
439 | // Just check that it is in the text area | |
440 | wxPoint pt = event.GetPosition(); | |
441 | if ( m_combo->GetTextRect().Contains(pt) ) | |
442 | { | |
443 | if ( evtType == wxEVT_LEFT_DOWN ) | |
444 | { | |
445 | // Set value to avoid up-events without corresponding downs | |
446 | m_downReceived = true; | |
447 | } | |
448 | else if ( evtType == wxEVT_LEFT_DCLICK ) | |
449 | { | |
450 | // We'll make our own double-clicks | |
451 | event.SetEventType(0); | |
452 | return; | |
453 | } | |
454 | else if ( evtType == wxEVT_LEFT_UP ) | |
455 | { | |
456 | if ( m_downReceived || m_timeLastMouseUp == 1 ) | |
457 | { | |
458 | wxLongLong timeFromLastUp = (t-m_timeLastMouseUp); | |
459 | ||
460 | if ( timeFromLastUp < DOUBLE_CLICK_CONVERSION_TRESHOLD ) | |
461 | { | |
462 | event.SetEventType(wxEVT_LEFT_DCLICK); | |
463 | m_timeLastMouseUp = 1; | |
464 | } | |
465 | else | |
466 | { | |
467 | m_timeLastMouseUp = t; | |
468 | } | |
469 | } | |
470 | } | |
471 | } | |
472 | } | |
473 | ||
474 | event.Skip(); | |
475 | } | |
476 | ||
477 | void OnSetFocus( wxFocusEvent& event ) | |
478 | { | |
479 | m_timeLastMouseUp = ::wxGetLocalTimeMillis(); | |
480 | event.Skip(); | |
481 | } | |
482 | ||
483 | private: | |
484 | wxLongLong m_timeLastMouseUp; | |
485 | wxOwnerDrawnComboBox* m_combo; | |
486 | wxPGProperty* m_property; // Selected property | |
487 | bool m_downReceived; | |
488 | ||
489 | DECLARE_EVENT_TABLE() | |
490 | }; | |
491 | ||
492 | BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor, wxEvtHandler) | |
493 | EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent) | |
494 | EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus) | |
495 | END_EVENT_TABLE() | |
496 | ||
497 | ||
498 | ||
499 | class wxPGComboBox : public wxOwnerDrawnComboBox | |
500 | { | |
501 | public: | |
502 | ||
503 | wxPGComboBox() | |
504 | : wxOwnerDrawnComboBox() | |
505 | { | |
506 | m_dclickProcessor = (wxPGDoubleClickProcessor*) NULL; | |
507 | m_sizeEventCalled = false; | |
508 | } | |
509 | ||
510 | ~wxPGComboBox() | |
511 | { | |
512 | if ( m_dclickProcessor ) | |
513 | { | |
514 | RemoveEventHandler(m_dclickProcessor); | |
515 | delete m_dclickProcessor; | |
516 | } | |
517 | } | |
518 | ||
519 | bool Create(wxWindow *parent, | |
520 | wxWindowID id, | |
521 | const wxString& value, | |
522 | const wxPoint& pos, | |
523 | const wxSize& size, | |
524 | const wxArrayString& choices, | |
525 | long style = 0, | |
526 | const wxValidator& validator = wxDefaultValidator, | |
527 | const wxString& name = wxS("wxOwnerDrawnComboBox")) | |
528 | { | |
529 | if ( !wxOwnerDrawnComboBox::Create( parent, | |
530 | id, | |
531 | value, | |
532 | pos, | |
533 | size, | |
534 | choices, | |
535 | style, | |
536 | validator, | |
537 | name ) ) | |
538 | return false; | |
539 | ||
e9cc4973 JS |
540 | m_dclickProcessor = new |
541 | wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() ); | |
1c4293cb VZ |
542 | |
543 | PushEventHandler(m_dclickProcessor); | |
544 | ||
545 | return true; | |
546 | } | |
547 | ||
e9cc4973 JS |
548 | virtual void OnDrawItem( wxDC& dc, |
549 | const wxRect& rect, | |
550 | int item, | |
551 | int flags ) const | |
1c4293cb VZ |
552 | { |
553 | wxPropertyGrid* pg = GetGrid(); | |
e9cc4973 | 554 | pg->OnComboItemPaint( this, item, &dc, (wxRect&)rect, flags ); |
1c4293cb | 555 | } |
e9cc4973 | 556 | |
1c4293cb VZ |
557 | virtual wxCoord OnMeasureItem( size_t item ) const |
558 | { | |
559 | wxPropertyGrid* pg = GetGrid(); | |
560 | wxRect rect; | |
561 | rect.x = -1; | |
562 | rect.width = 0; | |
e9cc4973 | 563 | pg->OnComboItemPaint( this, item, NULL, rect, 0 ); |
1c4293cb VZ |
564 | return rect.height; |
565 | } | |
566 | ||
567 | wxPropertyGrid* GetGrid() const | |
568 | { | |
e9cc4973 JS |
569 | wxPropertyGrid* pg = wxDynamicCast(GetParent()->GetParent(), |
570 | wxPropertyGrid); | |
1c4293cb VZ |
571 | wxASSERT(pg); |
572 | return pg; | |
573 | } | |
574 | ||
575 | virtual wxCoord OnMeasureItemWidth( size_t item ) const | |
576 | { | |
577 | wxPropertyGrid* pg = GetGrid(); | |
578 | wxRect rect; | |
579 | rect.x = -1; | |
580 | rect.width = -1; | |
e9cc4973 | 581 | pg->OnComboItemPaint( this, item, NULL, rect, 0 ); |
1c4293cb VZ |
582 | return rect.width; |
583 | } | |
584 | ||
e9cc4973 JS |
585 | virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust), |
586 | int WXUNUSED(textCtrlYAdjust) ) | |
1c4293cb VZ |
587 | { |
588 | wxPropertyGrid* pg = GetGrid(); | |
589 | wxOwnerDrawnComboBox::PositionTextCtrl( | |
e9cc4973 JS |
590 | wxPG_TEXTCTRLXADJUST - |
591 | (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1, | |
1c4293cb VZ |
592 | pg->GetSpacingY() + 2 |
593 | ); | |
594 | } | |
595 | ||
596 | private: | |
597 | wxPGDoubleClickProcessor* m_dclickProcessor; | |
598 | bool m_sizeEventCalled; | |
599 | }; | |
600 | ||
601 | ||
e9cc4973 | 602 | void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb, |
1c4293cb | 603 | int item, |
e9cc4973 | 604 | wxDC* pDc, |
1c4293cb VZ |
605 | wxRect& rect, |
606 | int flags ) | |
607 | { | |
1c4293cb VZ |
608 | // Sanity check |
609 | wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid)) ); | |
610 | ||
611 | wxPGProperty* p = m_selected; | |
612 | wxString text; | |
613 | ||
939d9364 | 614 | const wxPGChoices& choices = p->GetChoices(); |
1c4293cb | 615 | const wxPGCommonValue* comVal = NULL; |
1c4293cb VZ |
616 | int comVals = p->GetDisplayedCommonValueCount(); |
617 | int comValIndex = -1; | |
939d9364 JS |
618 | |
619 | int choiceCount = 0; | |
620 | if ( choices.IsOk() ) | |
621 | choiceCount = choices.GetCount(); | |
622 | ||
1c4293cb VZ |
623 | if ( item >= choiceCount && comVals > 0 ) |
624 | { | |
625 | comValIndex = item - choiceCount; | |
626 | comVal = GetCommonValue(comValIndex); | |
627 | if ( !p->IsValueUnspecified() ) | |
628 | text = comVal->GetLabel(); | |
629 | } | |
630 | else | |
631 | { | |
632 | if ( !(flags & wxODCB_PAINTING_CONTROL) ) | |
633 | { | |
634 | text = pCb->GetString(item); | |
635 | } | |
636 | else | |
637 | { | |
638 | if ( !p->IsValueUnspecified() ) | |
1425eca5 | 639 | text = p->GetValueAsString(0); |
1c4293cb VZ |
640 | } |
641 | } | |
642 | ||
643 | if ( item < 0 ) | |
644 | return; | |
645 | ||
646 | wxSize cis; | |
647 | ||
648 | const wxBitmap* itemBitmap = NULL; | |
649 | ||
939d9364 JS |
650 | if ( item >= 0 && choices.IsOk() && choices.Item(item).GetBitmap().Ok() && comValIndex == -1 ) |
651 | itemBitmap = &choices.Item(item).GetBitmap(); | |
1c4293cb VZ |
652 | |
653 | // | |
654 | // Decide what custom image size to use | |
655 | if ( itemBitmap ) | |
656 | { | |
657 | cis.x = itemBitmap->GetWidth(); | |
658 | cis.y = itemBitmap->GetHeight(); | |
659 | } | |
660 | else | |
661 | { | |
662 | cis = GetImageSize(p, item); | |
663 | } | |
664 | ||
665 | if ( rect.x < 0 ) | |
666 | { | |
667 | // Default measure behaviour (no flexible, custom paint image only) | |
668 | if ( rect.width < 0 ) | |
669 | { | |
670 | wxCoord x, y; | |
671 | GetTextExtent(text, &x, &y, 0, 0, &m_font); | |
672 | rect.width = cis.x + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2 + 9 + x; | |
673 | } | |
674 | ||
675 | rect.height = cis.y + 2; | |
676 | return; | |
677 | } | |
678 | ||
679 | wxPGPaintData paintdata; | |
680 | paintdata.m_parent = NULL; | |
681 | paintdata.m_choiceItem = item; | |
682 | ||
683 | // This is by the current (1.0.0b) spec - if painting control, item is -1 | |
684 | if ( (flags & wxODCB_PAINTING_CONTROL) ) | |
685 | paintdata.m_choiceItem = -1; | |
686 | ||
e9cc4973 JS |
687 | if ( pDc ) |
688 | pDc->SetBrush(*wxWHITE_BRUSH); | |
1c4293cb VZ |
689 | |
690 | if ( rect.x >= 0 ) | |
691 | { | |
692 | // | |
693 | // DrawItem call | |
e9cc4973 | 694 | wxDC& dc = *pDc; |
1c4293cb VZ |
695 | |
696 | wxPoint pt(rect.x + wxPG_CONTROL_MARGIN - wxPG_CHOICEXADJUST - 1, | |
697 | rect.y + 1); | |
698 | ||
d7e2b522 | 699 | int renderFlags = wxPGCellRenderer::DontUseCellColours; |
1c4293cb VZ |
700 | |
701 | if ( flags & wxODCB_PAINTING_CONTROL ) | |
702 | renderFlags |= wxPGCellRenderer::Control; | |
a2851207 JS |
703 | else |
704 | renderFlags |= wxPGCellRenderer::ChoicePopup; | |
1c4293cb VZ |
705 | |
706 | if ( flags & wxODCB_PAINTING_SELECTED ) | |
707 | renderFlags |= wxPGCellRenderer::Selected; | |
708 | ||
709 | if ( cis.x > 0 && (p->HasFlag(wxPG_PROP_CUSTOMIMAGE) || !(flags & wxODCB_PAINTING_CONTROL)) && | |
710 | ( !p->m_valueBitmap || item == pCb->GetSelection() ) && | |
711 | ( item >= 0 || (flags & wxODCB_PAINTING_CONTROL) ) && | |
712 | !itemBitmap | |
713 | ) | |
714 | { | |
715 | pt.x += wxCC_CUSTOM_IMAGE_MARGIN1; | |
716 | wxRect r(pt.x,pt.y,cis.x,cis.y); | |
717 | ||
718 | if ( flags & wxODCB_PAINTING_CONTROL ) | |
719 | { | |
720 | //r.width = cis.x; | |
721 | r.height = wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight); | |
722 | } | |
723 | ||
724 | paintdata.m_drawnWidth = r.width; | |
725 | ||
726 | dc.SetPen(m_colPropFore); | |
727 | if ( comValIndex >= 0 ) | |
728 | { | |
729 | const wxPGCommonValue* cv = GetCommonValue(comValIndex); | |
730 | wxPGCellRenderer* renderer = cv->GetRenderer(); | |
731 | r.width = rect.width; | |
732 | renderer->Render( dc, r, this, p, m_selColumn, comValIndex, renderFlags ); | |
733 | return; | |
734 | } | |
735 | else if ( item >= 0 ) | |
736 | { | |
737 | p->OnCustomPaint( dc, r, paintdata ); | |
738 | } | |
739 | else | |
740 | { | |
741 | dc.DrawRectangle( r ); | |
742 | } | |
743 | ||
744 | pt.x += paintdata.m_drawnWidth + wxCC_CUSTOM_IMAGE_MARGIN2 - 1; | |
745 | } | |
746 | else | |
747 | { | |
748 | // TODO: This aligns text so that it seems to be horizontally | |
749 | // on the same line as property values. Not really | |
750 | // sure if its needed, but seems to not cause any harm. | |
751 | pt.x -= 1; | |
752 | ||
753 | if ( item < 0 && (flags & wxODCB_PAINTING_CONTROL) ) | |
754 | item = pCb->GetSelection(); | |
755 | ||
939d9364 | 756 | if ( choices.IsOk() && item >= 0 && comValIndex < 0 ) |
1c4293cb | 757 | { |
939d9364 | 758 | const wxPGChoiceEntry& cell = choices.Item(item); |
1c4293cb VZ |
759 | wxPGCellRenderer* renderer = wxPGGlobalVars->m_defaultRenderer; |
760 | int imageOffset = renderer->PreDrawCell( dc, rect, cell, renderFlags ); | |
761 | if ( imageOffset ) | |
762 | imageOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2; | |
763 | pt.x += imageOffset; | |
764 | } | |
765 | } | |
766 | ||
767 | // | |
768 | // Draw text | |
769 | // | |
770 | ||
771 | pt.y += (rect.height-m_fontHeight)/2 - 1; | |
772 | ||
773 | pt.x += 1; | |
774 | ||
775 | dc.DrawText( text, pt.x + wxPG_XBEFORETEXT, pt.y ); | |
776 | } | |
777 | else | |
778 | { | |
779 | // | |
780 | // MeasureItem call | |
e9cc4973 | 781 | wxDC& dc = *pDc; |
1c4293cb VZ |
782 | |
783 | p->OnCustomPaint( dc, rect, paintdata ); | |
784 | rect.height = paintdata.m_drawnHeight + 2; | |
785 | rect.width = cis.x + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2 + 9; | |
786 | } | |
787 | } | |
788 | ||
789 | bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid* propGrid, wxPGComboBox* cb, int cmnVal ) | |
790 | { | |
791 | wxPGProperty* property = propGrid->GetSelectedProperty(); | |
792 | wxASSERT( property ); | |
793 | ||
794 | if ( cmnVal >= 0 ) | |
795 | { | |
796 | // Yes, a common value is being selected | |
797 | property->SetCommonValue( cmnVal ); | |
798 | wxSize imageSize = propGrid->GetCommonValue(cmnVal)-> | |
799 | GetRenderer()->GetImageSize(property, 1, cmnVal); | |
800 | if ( imageSize.x ) imageSize.x += ODCB_CUST_PAINT_MARGIN; | |
801 | cb->SetCustomPaintWidth( imageSize.x ); | |
802 | return false; | |
803 | } | |
804 | else | |
805 | { | |
806 | wxSize imageSize = propGrid->GetImageSize(property, -1); | |
807 | if ( imageSize.x ) imageSize.x += ODCB_CUST_PAINT_MARGIN; | |
808 | cb->SetCustomPaintWidth( imageSize.x ); | |
809 | return true; | |
810 | } | |
811 | } | |
812 | ||
813 | // CreateControls calls this with CB_READONLY in extraStyle | |
814 | wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid, | |
815 | wxPGProperty* property, | |
816 | const wxPoint& pos, | |
817 | const wxSize& sz, | |
818 | long extraStyle ) const | |
819 | { | |
939d9364 JS |
820 | const wxPGChoices& choices = property->GetChoices(); |
821 | wxString defString; | |
822 | int index = property->GetChoiceSelection(); | |
1c4293cb VZ |
823 | |
824 | bool isUnspecified = property->IsValueUnspecified(); | |
825 | ||
939d9364 | 826 | if ( !isUnspecified ) |
1c4293cb VZ |
827 | defString = property->GetDisplayedString(); |
828 | ||
1c4293cb VZ |
829 | wxArrayString labels = choices.GetLabels(); |
830 | ||
831 | wxPGComboBox* cb; | |
832 | ||
833 | wxPoint po(pos); | |
834 | wxSize si(sz); | |
835 | po.y += wxPG_CHOICEYADJUST; | |
836 | si.y -= (wxPG_CHOICEYADJUST*2); | |
837 | ||
838 | po.x += wxPG_CHOICEXADJUST; | |
839 | si.x -= wxPG_CHOICEXADJUST; | |
840 | wxWindow* ctrlParent = propGrid->GetPanel(); | |
841 | ||
7adf8bf3 | 842 | int odcbFlags = extraStyle | wxBORDER_NONE | wxTE_PROCESS_ENTER; |
1c4293cb VZ |
843 | |
844 | // | |
845 | // If common value specified, use appropriate index | |
846 | unsigned int cmnVals = property->GetDisplayedCommonValueCount(); | |
847 | if ( cmnVals ) | |
848 | { | |
849 | if ( !isUnspecified ) | |
850 | { | |
851 | int cmnVal = property->GetCommonValue(); | |
852 | if ( cmnVal >= 0 ) | |
853 | { | |
854 | index = labels.size() + cmnVal; | |
855 | } | |
856 | } | |
857 | ||
858 | unsigned int i; | |
859 | for ( i=0; i<cmnVals; i++ ) | |
860 | labels.Add(propGrid->GetCommonValueLabel(i)); | |
861 | } | |
862 | ||
863 | cb = new wxPGComboBox(); | |
864 | #ifdef __WXMSW__ | |
865 | cb->Hide(); | |
866 | #endif | |
867 | cb->Create(ctrlParent, | |
868 | wxPG_SUBID1, | |
869 | wxString(), | |
870 | po, | |
871 | si, | |
872 | labels, | |
873 | odcbFlags); | |
874 | ||
1c4293cb | 875 | cb->SetButtonPosition(si.y,0,wxRIGHT); |
1c4293cb VZ |
876 | cb->SetTextIndent(wxPG_XBEFORETEXT-1); |
877 | ||
878 | wxPGChoiceEditor_SetCustomPaintWidth( propGrid, cb, property->GetCommonValue() ); | |
1c4293cb VZ |
879 | |
880 | if ( index >= 0 && index < (int)cb->GetCount() ) | |
881 | { | |
882 | cb->SetSelection( index ); | |
883 | if ( defString.length() ) | |
884 | cb->SetText( defString ); | |
885 | } | |
886 | else if ( !(extraStyle & wxCB_READONLY) && defString.length() ) | |
887 | cb->SetValue( defString ); | |
888 | else | |
889 | cb->SetSelection( -1 ); | |
890 | ||
891 | #ifdef __WXMSW__ | |
892 | cb->Show(); | |
893 | #endif | |
894 | ||
895 | return (wxWindow*) cb; | |
896 | } | |
897 | ||
898 | ||
899 | void wxPGChoiceEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const | |
900 | { | |
901 | wxASSERT( ctrl ); | |
902 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
903 | wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox))); | |
939d9364 | 904 | int ind = property->GetChoiceSelection(); |
1c4293cb VZ |
905 | cb->SetSelection(ind); |
906 | } | |
907 | ||
908 | wxPGWindowList wxPGChoiceEditor::CreateControls( wxPropertyGrid* propGrid, wxPGProperty* property, | |
909 | const wxPoint& pos, const wxSize& sz ) const | |
910 | { | |
911 | return CreateControlsBase(propGrid,property,pos,sz,wxCB_READONLY); | |
912 | } | |
913 | ||
914 | ||
915 | int wxPGChoiceEditor::InsertItem( wxWindow* ctrl, const wxString& label, int index ) const | |
916 | { | |
917 | wxASSERT( ctrl ); | |
918 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
919 | wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox))); | |
920 | ||
921 | if (index < 0) | |
922 | index = cb->GetCount(); | |
923 | ||
924 | return cb->Insert(label,index); | |
925 | } | |
926 | ||
927 | ||
928 | void wxPGChoiceEditor::DeleteItem( wxWindow* ctrl, int index ) const | |
929 | { | |
930 | wxASSERT( ctrl ); | |
931 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
932 | wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox))); | |
933 | ||
934 | cb->Delete(index); | |
935 | } | |
936 | ||
937 | bool wxPGChoiceEditor::OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property, | |
938 | wxWindow* ctrl, wxEvent& event ) const | |
939 | { | |
940 | if ( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED ) | |
941 | { | |
942 | wxPGComboBox* cb = (wxPGComboBox*)ctrl; | |
943 | int index = cb->GetSelection(); | |
944 | int cmnValIndex = -1; | |
945 | int cmnVals = property->GetDisplayedCommonValueCount(); | |
946 | int items = cb->GetCount(); | |
947 | ||
948 | if ( index >= (items-cmnVals) ) | |
949 | { | |
950 | // Yes, a common value is being selected | |
951 | cmnValIndex = index - (items-cmnVals); | |
952 | property->SetCommonValue( cmnValIndex ); | |
953 | ||
954 | // Truly set value to unspecified? | |
955 | if ( propGrid->GetUnspecifiedCommonValue() == cmnValIndex ) | |
956 | { | |
957 | if ( !property->IsValueUnspecified() ) | |
958 | propGrid->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT); | |
959 | property->SetValueToUnspecified(); | |
960 | if ( !cb->HasFlag(wxCB_READONLY) ) | |
961 | cb->GetTextCtrl()->SetValue(wxEmptyString); | |
962 | return false; | |
963 | } | |
964 | } | |
965 | return wxPGChoiceEditor_SetCustomPaintWidth( propGrid, cb, cmnValIndex ); | |
966 | } | |
967 | return false; | |
968 | } | |
969 | ||
970 | ||
971 | bool wxPGChoiceEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const | |
972 | { | |
973 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
974 | ||
975 | int index = cb->GetSelection(); | |
976 | ||
939d9364 | 977 | if ( index != property->GetChoiceSelection() || |
1c4293cb VZ |
978 | // Changing unspecified always causes event (returning |
979 | // true here should be enough to trigger it). | |
980 | property->IsValueUnspecified() | |
981 | ) | |
982 | { | |
983 | return property->IntToValue( variant, index, 0 ); | |
984 | } | |
985 | return false; | |
986 | } | |
987 | ||
988 | ||
989 | void wxPGChoiceEditor::SetControlStringValue( wxPGProperty* WXUNUSED(property), wxWindow* ctrl, const wxString& txt ) const | |
990 | { | |
991 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
992 | wxASSERT( cb ); | |
993 | cb->SetValue(txt); | |
994 | } | |
995 | ||
996 | ||
997 | void wxPGChoiceEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow* ctrl, int value ) const | |
998 | { | |
999 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
1000 | wxASSERT( cb ); | |
1001 | cb->SetSelection(value); | |
1002 | } | |
1003 | ||
1004 | ||
1005 | void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* ctrl ) const | |
1006 | { | |
1007 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
1008 | cb->SetSelection(-1); | |
1009 | } | |
1010 | ||
1011 | ||
1012 | bool wxPGChoiceEditor::CanContainCustomImage() const | |
1013 | { | |
1014 | return true; | |
1015 | } | |
1016 | ||
1017 | ||
1018 | wxPGChoiceEditor::~wxPGChoiceEditor() { } | |
1019 | ||
1020 | ||
1021 | // ----------------------------------------------------------------------- | |
1022 | // wxPGComboBoxEditor | |
1023 | // ----------------------------------------------------------------------- | |
1024 | ||
1025 | ||
52cefafe JS |
1026 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox, |
1027 | wxPGComboBoxEditor, | |
1028 | wxPGChoiceEditor) | |
1c4293cb VZ |
1029 | |
1030 | ||
1031 | void wxPGComboBoxEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const | |
1032 | { | |
1033 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
1425eca5 | 1034 | cb->SetValue(property->GetValueAsString(wxPG_EDITABLE_VALUE)); |
1c4293cb VZ |
1035 | |
1036 | // TODO: If string matches any selection, then select that. | |
1037 | } | |
1038 | ||
1039 | ||
1040 | wxPGWindowList wxPGComboBoxEditor::CreateControls( wxPropertyGrid* propGrid, | |
1041 | wxPGProperty* property, | |
1042 | const wxPoint& pos, | |
1043 | const wxSize& sz ) const | |
1044 | { | |
1045 | return CreateControlsBase(propGrid,property,pos,sz,0); | |
1046 | } | |
1047 | ||
1048 | ||
1049 | bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid* propGrid, | |
1050 | wxPGProperty* property, | |
1051 | wxWindow* ctrl, | |
1052 | wxEvent& event ) const | |
1053 | { | |
1054 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*) NULL; | |
1055 | wxWindow* textCtrl = (wxWindow*) NULL; | |
1056 | ||
1057 | if ( ctrl ) | |
1058 | { | |
1059 | cb = (wxOwnerDrawnComboBox*)ctrl; | |
1060 | textCtrl = cb->GetTextCtrl(); | |
1061 | } | |
1062 | ||
1063 | if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid,property,textCtrl,event) ) | |
1064 | return true; | |
1065 | ||
1066 | return wxPGChoiceEditor::OnEvent(propGrid,property,ctrl,event); | |
1067 | } | |
1068 | ||
1069 | ||
1070 | bool wxPGComboBoxEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const | |
1071 | { | |
1072 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
1073 | wxString textVal = cb->GetValue(); | |
1074 | ||
1075 | if ( property->UsesAutoUnspecified() && !textVal.length() ) | |
1076 | { | |
1077 | variant.MakeNull(); | |
1078 | return true; | |
1079 | } | |
1080 | ||
1081 | bool res = property->StringToValue(variant, textVal, wxPG_EDITABLE_VALUE); | |
1082 | ||
1083 | // Changing unspecified always causes event (returning | |
1084 | // true here should be enough to trigger it). | |
1085 | if ( !res && variant.IsNull() ) | |
1086 | res = true; | |
1087 | ||
1088 | return res; | |
1089 | } | |
1090 | ||
1091 | ||
1092 | void wxPGComboBoxEditor::OnFocus( wxPGProperty*, wxWindow* ctrl ) const | |
1093 | { | |
1094 | wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl; | |
1095 | cb->GetTextCtrl()->SetSelection(-1,-1); | |
1096 | } | |
1097 | ||
1098 | ||
1099 | wxPGComboBoxEditor::~wxPGComboBoxEditor() { } | |
1100 | ||
1101 | ||
1102 | // ----------------------------------------------------------------------- | |
1103 | // wxPGChoiceAndButtonEditor | |
1104 | // ----------------------------------------------------------------------- | |
1105 | ||
1106 | ||
52cefafe JS |
1107 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton, |
1108 | wxPGChoiceAndButtonEditor, | |
1109 | wxPGChoiceEditor) | |
1c4293cb VZ |
1110 | |
1111 | ||
1112 | wxPGWindowList wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid* propGrid, | |
1113 | wxPGProperty* property, | |
1114 | const wxPoint& pos, | |
1115 | const wxSize& sz ) const | |
1116 | { | |
1117 | // Use one two units smaller to match size of the combo's dropbutton. | |
1118 | // (normally a bigger button is used because it looks better) | |
1119 | int bt_wid = sz.y; | |
1120 | bt_wid -= 2; | |
1121 | wxSize bt_sz(bt_wid,bt_wid); | |
1122 | ||
1123 | // Position of button. | |
1124 | wxPoint bt_pos(pos.x+sz.x-bt_sz.x,pos.y); | |
1125 | #ifdef __WXMAC__ | |
1126 | bt_pos.y -= 1; | |
1127 | #else | |
1128 | bt_pos.y += 1; | |
1129 | #endif | |
1130 | ||
1131 | wxWindow* bt = propGrid->GenerateEditorButton( bt_pos, bt_sz ); | |
1132 | ||
1133 | // Size of choice. | |
1134 | wxSize ch_sz(sz.x-bt->GetSize().x,sz.y); | |
1135 | ||
1136 | #ifdef __WXMAC__ | |
1137 | ch_sz.x -= wxPG_TEXTCTRL_AND_BUTTON_SPACING; | |
1138 | #endif | |
1139 | ||
c26873c8 | 1140 | wxWindow* ch = wxPGEditor_Choice->CreateControls(propGrid,property, |
1c4293cb VZ |
1141 | pos,ch_sz).m_primary; |
1142 | ||
1143 | #ifdef __WXMSW__ | |
1144 | bt->Show(); | |
1145 | #endif | |
1146 | ||
1147 | return wxPGWindowList(ch, bt); | |
1148 | } | |
1149 | ||
1150 | ||
1151 | wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { } | |
1152 | ||
1153 | ||
1154 | // ----------------------------------------------------------------------- | |
1155 | // wxPGTextCtrlAndButtonEditor | |
1156 | // ----------------------------------------------------------------------- | |
1157 | ||
52cefafe JS |
1158 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton, |
1159 | wxPGTextCtrlAndButtonEditor, | |
1160 | wxPGTextCtrlEditor) | |
1c4293cb VZ |
1161 | |
1162 | ||
1163 | wxPGWindowList wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid* propGrid, | |
1164 | wxPGProperty* property, | |
1165 | const wxPoint& pos, | |
1166 | const wxSize& sz ) const | |
1167 | { | |
1168 | wxWindow* wnd2; | |
1169 | wxWindow* wnd = propGrid->GenerateEditorTextCtrlAndButton( pos, sz, &wnd2, | |
1170 | property->GetFlags() & wxPG_PROP_NOEDITOR, property); | |
1171 | ||
1172 | return wxPGWindowList(wnd, wnd2); | |
1173 | } | |
1174 | ||
1175 | ||
1176 | wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { } | |
1177 | ||
1178 | ||
1179 | // ----------------------------------------------------------------------- | |
1180 | // wxPGCheckBoxEditor | |
1181 | // ----------------------------------------------------------------------- | |
1182 | ||
1183 | #if wxPG_INCLUDE_CHECKBOX | |
1184 | ||
52cefafe JS |
1185 | WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox, |
1186 | wxPGCheckBoxEditor, | |
1187 | wxPGEditor) | |
1c4293cb VZ |
1188 | |
1189 | ||
1190 | // state argument: 0x01 = set if checked | |
1191 | // 0x02 = set if rectangle should be bold | |
1192 | static void DrawSimpleCheckBox( wxDC& dc, const wxRect& rect, int box_hei, int state, const wxColour& linecol ) | |
1193 | { | |
1194 | ||
1195 | // Box rectangle. | |
1196 | wxRect r(rect.x+wxPG_XBEFORETEXT,rect.y+((rect.height-box_hei)/2),box_hei,box_hei); | |
1197 | ||
1198 | // Draw check mark first because it is likely to overdraw the | |
1199 | // surrounding rectangle. | |
1200 | if ( state & 1 ) | |
1201 | { | |
1202 | wxRect r2(r.x+wxPG_CHECKMARK_XADJ, | |
1203 | r.y+wxPG_CHECKMARK_YADJ, | |
1204 | r.width+wxPG_CHECKMARK_WADJ, | |
1205 | r.height+wxPG_CHECKMARK_HADJ); | |
1206 | #if wxPG_CHECKMARK_DEFLATE | |
1207 | r2.Deflate(wxPG_CHECKMARK_DEFLATE); | |
1208 | #endif | |
1209 | dc.DrawCheckMark(r2); | |
1210 | ||
1211 | // This would draw a simple cross check mark. | |
1212 | // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1); | |
1213 | // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y); | |
1214 | ||
1215 | } | |
1216 | ||
1217 | if ( !(state & 2) ) | |
1218 | { | |
1219 | // Pen for thin rectangle. | |
1220 | dc.SetPen(linecol); | |
1221 | } | |
1222 | else | |
1223 | { | |
1224 | // Pen for bold rectangle. | |
1225 | wxPen linepen(linecol,2,wxSOLID); | |
1226 | linepen.SetJoin(wxJOIN_MITER); // This prevents round edges. | |
1227 | dc.SetPen(linepen); | |
1228 | r.x++; | |
1229 | r.y++; | |
1230 | r.width--; | |
1231 | r.height--; | |
1232 | } | |
1233 | ||
1234 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1235 | ||
1236 | dc.DrawRectangle(r); | |
1237 | dc.SetPen(*wxTRANSPARENT_PEN); | |
1238 | } | |
1239 | ||
1240 | // | |
1241 | // Real simple custom-drawn checkbox-without-label class. | |
1242 | // | |
1243 | class wxSimpleCheckBox : public wxControl | |
1244 | { | |
1245 | public: | |
1246 | ||
1247 | void SetValue( int value ); | |
1248 | ||
1249 | wxSimpleCheckBox( wxWindow* parent, | |
1250 | wxWindowID id, | |
1251 | const wxPoint& pos = wxDefaultPosition, | |
1252 | const wxSize& size = wxDefaultSize ) | |
7adf8bf3 | 1253 | : wxControl(parent,id,pos,size,wxBORDER_NONE|wxWANTS_CHARS) |
1c4293cb VZ |
1254 | { |
1255 | // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this | |
1256 | SetFont( parent->GetFont() ); | |
1257 | ||
1258 | m_state = 0; | |
1259 | wxPropertyGrid* pg = (wxPropertyGrid*) parent->GetParent(); | |
1260 | wxASSERT( pg->IsKindOf(CLASSINFO(wxPropertyGrid)) ); | |
1261 | m_boxHeight = pg->GetFontHeight(); | |
1262 | SetBackgroundStyle( wxBG_STYLE_COLOUR ); | |
1263 | } | |
1264 | ||
1265 | virtual ~wxSimpleCheckBox(); | |
1266 | ||
1267 | virtual bool ProcessEvent(wxEvent& event); | |
1268 | ||
1269 | int m_state; | |
1270 | int m_boxHeight; | |
1271 | ||
1272 | static wxBitmap* ms_doubleBuffer; | |
1273 | ||
1274 | }; | |
1275 | ||
1276 | wxSimpleCheckBox::~wxSimpleCheckBox() | |
1277 | { | |
1278 | delete ms_doubleBuffer; | |
1279 | ms_doubleBuffer = NULL; | |
1280 | } | |
1281 | ||
1282 | ||
1283 | wxBitmap* wxSimpleCheckBox::ms_doubleBuffer = (wxBitmap*) NULL; | |
1284 | ||
1285 | // value = 2 means toggle (sorry, too lazy to do constants) | |
1286 | void wxSimpleCheckBox::SetValue( int value ) | |
1287 | { | |
1288 | if ( value > 1 ) | |
1289 | { | |
1290 | m_state++; | |
1291 | if ( m_state > 1 ) m_state = 0; | |
1292 | } | |
1293 | else | |
1294 | { | |
1295 | m_state = value; | |
1296 | } | |
1297 | Refresh(); | |
1298 | ||
1299 | wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED,GetParent()->GetId()); | |
1300 | ||
1301 | wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent(); | |
1302 | wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) ); | |
b0996c3d | 1303 | propGrid->HandleCustomEditorEvent(evt); |
1c4293cb VZ |
1304 | } |
1305 | ||
1306 | ||
1307 | bool wxSimpleCheckBox::ProcessEvent(wxEvent& event) | |
1308 | { | |
1309 | wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent(); | |
1310 | wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) ); | |
1311 | ||
1c4293cb VZ |
1312 | if ( ( (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK) |
1313 | && ((wxMouseEvent&)event).m_x > (wxPG_XBEFORETEXT-2) | |
1314 | && ((wxMouseEvent&)event).m_x <= (wxPG_XBEFORETEXT-2+m_boxHeight) ) | |
1315 | ) | |
1316 | { | |
1317 | SetValue(2); | |
1318 | return true; | |
1319 | } | |
1320 | else if ( event.GetEventType() == wxEVT_PAINT ) | |
1321 | { | |
1322 | wxSize clientSize = GetClientSize(); | |
1323 | wxPaintDC dc(this); | |
1324 | ||
1325 | /* | |
1326 | // Buffered paint DC doesn't seem to do much good | |
1327 | if ( !ms_doubleBuffer || | |
1328 | clientSize.x > ms_doubleBuffer->GetWidth() || | |
1329 | clientSize.y > ms_doubleBuffer->GetHeight() ) | |
1330 | { | |
1331 | delete ms_doubleBuffer; | |
1332 | ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25); | |
1333 | } | |
1334 | ||
1335 | wxBufferedPaintDC dc(this,*ms_doubleBuffer); | |
1336 | */ | |
1337 | ||
1338 | wxRect rect(0,0,clientSize.x,clientSize.y); | |
1339 | //rect.x -= 1; | |
1340 | rect.y += 1; | |
1341 | rect.width += 1; | |
1342 | ||
1343 | m_boxHeight = propGrid->GetFontHeight(); | |
1344 | ||
1345 | wxColour bgcol = GetBackgroundColour(); | |
1346 | dc.SetBrush( bgcol ); | |
1347 | dc.SetPen( bgcol ); | |
1348 | dc.DrawRectangle( rect ); | |
1349 | ||
1350 | wxColour txcol = GetForegroundColour(); | |
1351 | ||
1352 | int state = m_state; | |
1353 | if ( m_font.GetWeight() == wxBOLD ) | |
1354 | state |= 2; | |
1355 | ||
1356 | DrawSimpleCheckBox(dc,rect,m_boxHeight,state,txcol); | |
1357 | ||
1358 | // If focused, indicate it somehow. | |
1359 | /* | |
1360 | if ( wxWindow::FindFocus() == this ) | |
1361 | { | |
1362 | rect.x += 1; | |
1363 | rect.width -= 1; | |
1364 | ||
1365 | wxPGDrawFocusRect(dc,rect); | |
1366 | } | |
1367 | */ | |
1368 | ||
1369 | return true; | |
1370 | } | |
1371 | else if ( event.GetEventType() == wxEVT_SIZE || | |
1372 | event.GetEventType() == wxEVT_SET_FOCUS || | |
1373 | event.GetEventType() == wxEVT_KILL_FOCUS | |
1374 | ) | |
1375 | { | |
1376 | Refresh(); | |
1377 | } | |
1378 | else if ( event.GetEventType() == wxEVT_KEY_DOWN ) | |
1379 | { | |
1380 | wxKeyEvent& keyEv = (wxKeyEvent&) event; | |
1381 | ||
1c4293cb VZ |
1382 | if ( keyEv.GetKeyCode() == WXK_SPACE ) |
1383 | { | |
1384 | SetValue(2); | |
1385 | return true; | |
1386 | } | |
1387 | } | |
1388 | return wxControl::ProcessEvent(event); | |
1389 | } | |
1390 | ||
1391 | ||
1392 | wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid, | |
1393 | wxPGProperty* property, | |
1394 | const wxPoint& pos, | |
1395 | const wxSize& size ) const | |
1396 | { | |
1397 | wxPoint pt = pos; | |
1398 | pt.x -= wxPG_XBEFOREWIDGET; | |
1399 | wxSize sz = size; | |
1400 | sz.x = propGrid->GetFontHeight() + (wxPG_XBEFOREWIDGET*2) + 4; | |
1401 | ||
1402 | wxSimpleCheckBox* cb = new wxSimpleCheckBox(propGrid->GetPanel(),wxPG_SUBID1,pt,sz); | |
1403 | ||
1404 | cb->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); | |
1405 | ||
939d9364 | 1406 | if ( property->GetChoiceSelection() > 0 && |
1c4293cb VZ |
1407 | !property->IsValueUnspecified() ) |
1408 | cb->m_state = 1; | |
1409 | ||
1410 | // If mouse cursor was on the item, toggle the value now. | |
1411 | if ( propGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK ) | |
1412 | { | |
1413 | wxPoint pt = cb->ScreenToClient(::wxGetMousePosition()); | |
1414 | if ( pt.x <= (wxPG_XBEFORETEXT-2+cb->m_boxHeight) ) | |
1415 | { | |
1416 | cb->m_state++; | |
1417 | ||
1418 | if ( cb->m_state > 1 ) | |
1419 | cb->m_state = 0; | |
1420 | ||
1421 | // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click | |
1422 | propGrid->ChangePropertyValue(property, wxPGVariant_Bool(cb->m_state)); | |
1423 | } | |
1424 | } | |
1425 | ||
1426 | propGrid->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR ); | |
1427 | ||
1428 | return cb; | |
1429 | } | |
1430 | ||
1431 | /* | |
1432 | class wxPGCheckBoxRenderer : public wxPGDefaultRenderer | |
1433 | { | |
1434 | public: | |
1435 | ||
1436 | virtual void Render( wxDC& dc, const wxRect& rect, | |
1437 | const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property, | |
1438 | int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const | |
1439 | { | |
1440 | int state = 0; | |
1441 | if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) ) | |
1442 | { | |
1443 | state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL); | |
1444 | if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2; | |
1445 | } | |
1446 | DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground()); | |
1447 | } | |
1448 | ||
1449 | protected: | |
1450 | }; | |
1451 | ||
1452 | wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer; | |
1453 | ||
1454 | wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const | |
1455 | { | |
1456 | return &g_wxPGCheckBoxRenderer; | |
1457 | } | |
1458 | */ | |
1459 | ||
1460 | void wxPGCheckBoxEditor::DrawValue( wxDC& dc, const wxRect& rect, wxPGProperty* property, const wxString& WXUNUSED(text) ) const | |
1461 | { | |
1462 | int state = 0; | |
1463 | if ( !property->IsValueUnspecified() ) | |
1464 | { | |
939d9364 | 1465 | state = property->GetChoiceSelection(); |
1c4293cb VZ |
1466 | if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2; |
1467 | } | |
1468 | DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground()); | |
1469 | } | |
1470 | ||
1471 | void wxPGCheckBoxEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const | |
1472 | { | |
1473 | wxASSERT( ctrl ); | |
939d9364 | 1474 | ((wxSimpleCheckBox*)ctrl)->m_state = property->GetChoiceSelection(); |
1c4293cb VZ |
1475 | ctrl->Refresh(); |
1476 | } | |
1477 | ||
1478 | ||
1479 | bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid* WXUNUSED(propGrid), wxPGProperty* WXUNUSED(property), | |
1480 | wxWindow* WXUNUSED(ctrl), wxEvent& event ) const | |
1481 | { | |
1482 | if ( event.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED ) | |
1483 | { | |
1484 | return true; | |
1485 | } | |
1486 | return false; | |
1487 | } | |
1488 | ||
1489 | ||
1490 | bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const | |
1491 | { | |
1492 | wxSimpleCheckBox* cb = (wxSimpleCheckBox*)ctrl; | |
1493 | ||
1494 | int index = cb->m_state; | |
1495 | ||
939d9364 | 1496 | if ( index != property->GetChoiceSelection() || |
1c4293cb VZ |
1497 | // Changing unspecified always causes event (returning |
1498 | // true here should be enough to trigger it). | |
1499 | property->IsValueUnspecified() | |
1500 | ) | |
1501 | { | |
1502 | return property->IntToValue(variant, index, 0); | |
1503 | } | |
1504 | return false; | |
1505 | } | |
1506 | ||
1507 | ||
1508 | void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow* ctrl, int value ) const | |
1509 | { | |
1510 | if ( value != 0 ) value = 1; | |
1511 | ((wxSimpleCheckBox*)ctrl)->m_state = value; | |
1512 | ctrl->Refresh(); | |
1513 | } | |
1514 | ||
1515 | ||
1516 | void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* ctrl ) const | |
1517 | { | |
1518 | ((wxSimpleCheckBox*)ctrl)->m_state = 0; | |
1519 | ctrl->Refresh(); | |
1520 | } | |
1521 | ||
1522 | ||
1523 | wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { } | |
1524 | ||
1525 | ||
1526 | #endif // wxPG_INCLUDE_CHECKBOX | |
1527 | ||
1528 | // ----------------------------------------------------------------------- | |
1529 | ||
1530 | wxWindow* wxPropertyGrid::GetEditorControl() const | |
1531 | { | |
1532 | wxWindow* ctrl = m_wndEditor; | |
1533 | ||
1534 | if ( !ctrl ) | |
1535 | return ctrl; | |
1536 | ||
1c4293cb VZ |
1537 | return ctrl; |
1538 | } | |
1539 | ||
1540 | // ----------------------------------------------------------------------- | |
1541 | ||
1542 | void wxPropertyGrid::CorrectEditorWidgetSizeX() | |
1543 | { | |
1544 | if ( m_selColumn == -1 ) | |
1545 | return; | |
1546 | ||
1547 | int secWid = 0; | |
1548 | int newSplitterx = m_pState->DoGetSplitterPosition(m_selColumn-1); | |
1549 | int newWidth = newSplitterx + m_pState->m_colWidths[m_selColumn]; | |
1550 | ||
1551 | if ( m_wndEditor2 ) | |
1552 | { | |
1553 | // if width change occurred, move secondary wnd by that amount | |
1554 | wxRect r = m_wndEditor2->GetRect(); | |
1555 | secWid = r.width; | |
1556 | r.x = newWidth - secWid; | |
1557 | ||
1558 | m_wndEditor2->SetSize( r ); | |
1559 | ||
1560 | // if primary is textctrl, then we have to add some extra space | |
1561 | #ifdef __WXMAC__ | |
1562 | if ( m_wndEditor ) | |
1563 | #else | |
1564 | if ( m_wndEditor && m_wndEditor->IsKindOf(CLASSINFO(wxTextCtrl)) ) | |
1565 | #endif | |
1566 | secWid += wxPG_TEXTCTRL_AND_BUTTON_SPACING; | |
1567 | } | |
1568 | ||
1569 | if ( m_wndEditor ) | |
1570 | { | |
1571 | wxRect r = m_wndEditor->GetRect(); | |
1572 | ||
1573 | r.x = newSplitterx+m_ctrlXAdjust; | |
1574 | ||
1575 | if ( !(m_iFlags & wxPG_FL_FIXED_WIDTH_EDITOR) ) | |
1576 | r.width = newWidth - r.x - secWid; | |
1577 | ||
1578 | m_wndEditor->SetSize(r); | |
1579 | } | |
1580 | ||
1581 | if ( m_wndEditor2 ) | |
1582 | m_wndEditor2->Refresh(); | |
1583 | } | |
1584 | ||
1585 | // ----------------------------------------------------------------------- | |
1586 | ||
1587 | void wxPropertyGrid::CorrectEditorWidgetPosY() | |
1588 | { | |
aace2c4f JS |
1589 | if ( m_selColumn == -1 ) |
1590 | return; | |
1591 | ||
1c4293cb VZ |
1592 | if ( m_selected && (m_wndEditor || m_wndEditor2) ) |
1593 | { | |
1594 | wxRect r = GetEditorWidgetRect(m_selected, m_selColumn); | |
1595 | ||
1596 | if ( m_wndEditor ) | |
1597 | { | |
1598 | wxPoint pos = m_wndEditor->GetPosition(); | |
1599 | ||
1600 | // Calculate y offset | |
1601 | int offset = pos.y % m_lineHeight; | |
1602 | ||
1603 | m_wndEditor->Move(pos.x, r.y + offset); | |
1604 | } | |
1605 | ||
1606 | if ( m_wndEditor2 ) | |
1607 | { | |
1608 | wxPoint pos = m_wndEditor2->GetPosition(); | |
1609 | ||
1610 | m_wndEditor2->Move(pos.x, r.y); | |
1611 | } | |
1612 | } | |
1613 | } | |
1614 | ||
1615 | // ----------------------------------------------------------------------- | |
1616 | ||
1c4293cb VZ |
1617 | // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually |
1618 | // fits into that category as well). | |
1619 | void wxPropertyGrid::FixPosForTextCtrl( wxWindow* ctrl, const wxPoint& offset ) | |
1620 | { | |
1621 | // Center the control vertically | |
1622 | wxRect finalPos = ctrl->GetRect(); | |
1623 | int y_adj = (m_lineHeight - finalPos.height)/2 + wxPG_TEXTCTRLYADJUST; | |
1624 | ||
1625 | // Prevent over-sized control | |
1626 | int sz_dec = (y_adj + finalPos.height) - m_lineHeight; | |
1627 | if ( sz_dec < 0 ) sz_dec = 0; | |
1628 | ||
1629 | finalPos.y += y_adj; | |
1630 | finalPos.height -= (y_adj+sz_dec); | |
1631 | ||
1632 | const int textCtrlXAdjust = wxPG_TEXTCTRLXADJUST; | |
1633 | ||
1634 | finalPos.x += textCtrlXAdjust; | |
1635 | finalPos.width -= textCtrlXAdjust; | |
1636 | ||
1637 | finalPos.x += offset.x; | |
1638 | finalPos.y += offset.y; | |
1639 | ||
1640 | ctrl->SetSize(finalPos); | |
1641 | } | |
1642 | ||
1643 | // ----------------------------------------------------------------------- | |
1644 | ||
1645 | wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos, | |
1646 | const wxSize& sz, | |
1647 | const wxString& value, | |
1648 | wxWindow* secondary, | |
1649 | int extraStyle, | |
1650 | int maxLen ) | |
1651 | { | |
d9fb481c | 1652 | wxWindowID id = wxPG_SUBID1; |
1c4293cb VZ |
1653 | wxPGProperty* selected = m_selected; |
1654 | wxASSERT(selected); | |
1655 | ||
1656 | int tcFlags = wxTE_PROCESS_ENTER | extraStyle; | |
1657 | ||
1658 | if ( selected->HasFlag(wxPG_PROP_READONLY) ) | |
1659 | tcFlags |= wxTE_READONLY; | |
1660 | ||
1661 | wxPoint p(pos.x,pos.y); | |
1662 | wxSize s(sz.x,sz.y); | |
1663 | ||
1664 | // Need to reduce width of text control on Mac | |
1665 | #if defined(__WXMAC__) | |
012b4a07 | 1666 | s.x -= 8; |
1c4293cb VZ |
1667 | #endif |
1668 | ||
1669 | // Take button into acccount | |
1670 | if ( secondary ) | |
1671 | { | |
1672 | s.x -= (secondary->GetSize().x + wxPG_TEXTCTRL_AND_BUTTON_SPACING); | |
1673 | m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE); | |
1674 | } | |
1675 | ||
1676 | // If the height is significantly higher, then use border, and fill the rect exactly. | |
1677 | bool hasSpecialSize = false; | |
1678 | ||
1679 | if ( (sz.y - m_lineHeight) > 5 ) | |
1680 | hasSpecialSize = true; | |
1681 | ||
1c4293cb VZ |
1682 | wxWindow* ctrlParent = GetPanel(); |
1683 | ||
1684 | if ( !hasSpecialSize ) | |
7adf8bf3 | 1685 | tcFlags |= wxBORDER_NONE; |
1c4293cb VZ |
1686 | |
1687 | wxTextCtrl* tc = new wxTextCtrl(); | |
1688 | ||
7adf8bf3 | 1689 | #if defined(__WXMSW__) |
1c4293cb VZ |
1690 | tc->Hide(); |
1691 | #endif | |
1692 | SetupTextCtrlValue(value); | |
d9fb481c | 1693 | tc->Create(ctrlParent,id,value, p, s,tcFlags); |
012b4a07 | 1694 | |
1c4293cb | 1695 | wxWindow* ed = tc; |
1c4293cb VZ |
1696 | |
1697 | // Center the control vertically | |
1698 | if ( !hasSpecialSize ) | |
1699 | FixPosForTextCtrl(ed); | |
1700 | ||
1701 | #ifdef __WXMSW__ | |
1702 | ed->Show(); | |
1703 | if ( secondary ) | |
1704 | secondary->Show(); | |
1705 | #endif | |
1706 | ||
1707 | // Set maximum length | |
1708 | if ( maxLen > 0 ) | |
1709 | tc->SetMaxLength( maxLen ); | |
1710 | ||
1711 | return (wxWindow*) ed; | |
1712 | } | |
1713 | ||
1714 | // ----------------------------------------------------------------------- | |
1715 | ||
1716 | wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize& sz ) | |
1717 | { | |
d9fb481c | 1718 | wxWindowID id = wxPG_SUBID2; |
1c4293cb VZ |
1719 | wxPGProperty* selected = m_selected; |
1720 | wxASSERT(selected); | |
1721 | ||
1722 | #ifdef __WXMAC__ | |
1723 | // Decorations are chunky on Mac, and we can't make the button square, so | |
1724 | // do things a bit differently on this platform. | |
1725 | ||
1726 | wxPoint p(pos.x+sz.x, | |
1727 | pos.y+wxPG_BUTTON_SIZEDEC-wxPG_NAT_BUTTON_BORDER_Y); | |
1728 | wxSize s(25, -1); | |
1729 | ||
1730 | wxButton* but = new wxButton(); | |
d9fb481c | 1731 | but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS); |
1c4293cb VZ |
1732 | |
1733 | // Now that we know the size, move to the correct position | |
1734 | p.x = pos.x + sz.x - but->GetSize().x - 2; | |
1735 | but->Move(p); | |
1736 | ||
1737 | #else | |
1738 | wxSize s(sz.y-(wxPG_BUTTON_SIZEDEC*2)+(wxPG_NAT_BUTTON_BORDER_Y*2), | |
1739 | sz.y-(wxPG_BUTTON_SIZEDEC*2)+(wxPG_NAT_BUTTON_BORDER_Y*2)); | |
1740 | ||
1741 | // Reduce button width to lineheight | |
1742 | if ( s.x > m_lineHeight ) | |
1743 | s.x = m_lineHeight; | |
1744 | ||
d863389f JS |
1745 | #ifdef __WXGTK__ |
1746 | // On wxGTK, take fixed button margins into account | |
1747 | if ( s.x < 25 ) | |
1748 | s.x = 25; | |
1749 | #endif | |
1750 | ||
1c4293cb VZ |
1751 | wxPoint p(pos.x+sz.x-s.x, |
1752 | pos.y+wxPG_BUTTON_SIZEDEC-wxPG_NAT_BUTTON_BORDER_Y); | |
1753 | ||
1754 | wxButton* but = new wxButton(); | |
d863389f | 1755 | #ifdef __WXMSW__ |
1c4293cb | 1756 | but->Hide(); |
d863389f | 1757 | #endif |
d9fb481c | 1758 | but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS); |
1c4293cb | 1759 | |
d863389f JS |
1760 | #ifdef __WXGTK__ |
1761 | wxFont font = GetFont(); | |
1762 | font.SetPointSize(font.GetPointSize()-2); | |
1763 | but->SetFont(font); | |
1764 | #else | |
1765 | but->SetFont(GetFont()); | |
1766 | #endif | |
1c4293cb VZ |
1767 | #endif |
1768 | ||
1769 | if ( selected->HasFlag(wxPG_PROP_READONLY) ) | |
1770 | but->Disable(); | |
1771 | ||
1772 | return but; | |
1773 | } | |
1774 | ||
1775 | // ----------------------------------------------------------------------- | |
1776 | ||
1777 | wxWindow* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint& pos, | |
1778 | const wxSize& sz, | |
1779 | wxWindow** psecondary, | |
1780 | int limitedEditing, | |
1781 | wxPGProperty* property ) | |
1782 | { | |
1783 | wxButton* but = (wxButton*)GenerateEditorButton(pos,sz); | |
1784 | *psecondary = (wxWindow*)but; | |
1785 | ||
1786 | if ( limitedEditing ) | |
1787 | { | |
1788 | #ifdef __WXMSW__ | |
1789 | // There is button Show in GenerateEditorTextCtrl as well | |
1790 | but->Show(); | |
1791 | #endif | |
1792 | return (wxWindow*) NULL; | |
1793 | } | |
1794 | ||
1795 | wxString text; | |
1796 | ||
1797 | if ( !property->IsValueUnspecified() ) | |
1425eca5 | 1798 | text = property->GetValueAsString(property->HasFlag(wxPG_PROP_READONLY)?0:wxPG_EDITABLE_VALUE); |
1c4293cb VZ |
1799 | |
1800 | return GenerateEditorTextCtrl(pos,sz,text,but,property->m_maxLen); | |
1801 | } | |
1802 | ||
1803 | // ----------------------------------------------------------------------- | |
1804 | ||
1805 | wxTextCtrl* wxPropertyGrid::GetEditorTextCtrl() const | |
1806 | { | |
1807 | wxWindow* wnd = GetEditorControl(); | |
1808 | ||
1809 | if ( !wnd ) | |
1810 | return NULL; | |
1811 | ||
1812 | if ( wnd->IsKindOf(CLASSINFO(wxTextCtrl)) ) | |
1813 | return wxStaticCast(wnd, wxTextCtrl); | |
1814 | ||
1815 | if ( wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) ) | |
1816 | { | |
1817 | wxOwnerDrawnComboBox* cb = wxStaticCast(wnd, wxOwnerDrawnComboBox); | |
1818 | return cb->GetTextCtrl(); | |
1819 | } | |
1820 | ||
1821 | return NULL; | |
1822 | } | |
1823 | ||
1824 | // ----------------------------------------------------------------------- | |
1825 | ||
1826 | wxPGEditor* wxPropertyGridInterface::GetEditorByName( const wxString& editorName ) | |
1827 | { | |
1828 | wxPGHashMapS2P::const_iterator it; | |
1829 | ||
1830 | it = wxPGGlobalVars->m_mapEditorClasses.find(editorName); | |
1831 | if ( it == wxPGGlobalVars->m_mapEditorClasses.end() ) | |
1832 | return NULL; | |
1833 | return (wxPGEditor*) it->second; | |
1834 | } | |
1835 | ||
1836 | // ----------------------------------------------------------------------- | |
1837 | // wxPGEditorDialogAdapter | |
1838 | // ----------------------------------------------------------------------- | |
1839 | ||
1840 | IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter, wxObject) | |
1841 | ||
1842 | bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid* propGrid, wxPGProperty* property ) | |
1843 | { | |
1844 | if ( !propGrid->EditorValidate() ) | |
1845 | return false; | |
1846 | ||
1847 | bool res = DoShowDialog( propGrid, property ); | |
1848 | ||
1849 | if ( res ) | |
1850 | { | |
1851 | propGrid->ValueChangeInEvent( m_value ); | |
1852 | return true; | |
1853 | } | |
1854 | ||
1855 | return false; | |
1856 | } | |
1857 | ||
1858 | // ----------------------------------------------------------------------- | |
1859 | // wxPGMultiButton | |
1860 | // ----------------------------------------------------------------------- | |
1861 | ||
1862 | wxPGMultiButton::wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz ) | |
1863 | : wxWindow( pg->GetPanel(), wxPG_SUBID2, wxPoint(-100,-100), wxSize(0, sz.y) ), | |
1864 | m_fullEditorSize(sz), m_buttonsWidth(0) | |
1865 | { | |
1866 | SetBackgroundColour(pg->GetCellBackgroundColour()); | |
1867 | } | |
1868 | ||
b0996c3d JS |
1869 | void wxPGMultiButton::Finalize( wxPropertyGrid* WXUNUSED(propGrid), |
1870 | const wxPoint& pos ) | |
7a344f1b JS |
1871 | { |
1872 | Move( pos.x + m_fullEditorSize.x - m_buttonsWidth, pos.y ); | |
7a344f1b JS |
1873 | } |
1874 | ||
1c4293cb VZ |
1875 | int wxPGMultiButton::GenId( int id ) const |
1876 | { | |
1877 | if ( id < -1 ) | |
1878 | { | |
1879 | if ( m_buttons.size() ) | |
1880 | id = GetButton(m_buttons.size()-1)->GetId() + 1; | |
1881 | else | |
1882 | id = wxPG_SUBID2; | |
1883 | } | |
1884 | return id; | |
1885 | } | |
1886 | ||
1887 | #if wxUSE_BMPBUTTON | |
1888 | void wxPGMultiButton::Add( const wxBitmap& bitmap, int id ) | |
1889 | { | |
1890 | id = GenId(id); | |
1891 | wxSize sz = GetSize(); | |
1892 | wxButton* button = new wxBitmapButton( this, id, bitmap, wxPoint(sz.x, 0), wxSize(sz.y, sz.y) ); | |
1893 | m_buttons.push_back(button); | |
1894 | int bw = button->GetSize().x; | |
1895 | SetSize(wxSize(sz.x+bw,sz.y)); | |
1896 | m_buttonsWidth += bw; | |
1897 | } | |
1898 | #endif | |
1899 | ||
1900 | void wxPGMultiButton::Add( const wxString& label, int id ) | |
1901 | { | |
1902 | id = GenId(id); | |
1903 | wxSize sz = GetSize(); | |
1904 | wxButton* button = new wxButton( this, id, label, wxPoint(sz.x, 0), wxSize(sz.y, sz.y) ); | |
1905 | m_buttons.push_back(button); | |
1906 | int bw = button->GetSize().x; | |
1907 | SetSize(wxSize(sz.x+bw,sz.y)); | |
1908 | m_buttonsWidth += bw; | |
1909 | } | |
1910 | ||
1911 | // ----------------------------------------------------------------------- | |
f4bc1aa2 JS |
1912 | |
1913 | #endif // wxUSE_PROPGRID |