]> git.saurik.com Git - wxWidgets.git/blob - src/motif/listbox.cpp
Corrected XPM-related cast in resource.cpp; added generic Blitting code in wxPostScriptDC
[wxWidgets.git] / src / motif / listbox.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: listbox.cpp
3 // Purpose: wxListBox
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "listbox.h"
14 #endif
15
16 #include "wx/listbox.h"
17 #include "wx/settings.h"
18 #include "wx/dynarray.h"
19 #include "wx/log.h"
20 #include "wx/utils.h"
21
22 #include <Xm/List.h>
23 #include "wx/motif/private.h"
24
25 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
27 #endif
28
29 void wxListBoxCallback (Widget w, XtPointer clientData,
30 XmListCallbackStruct * cbs);
31
32 void wxListBoxDefaultActionProc (Widget list_w, XtPointer client_data, XmListCallbackStruct * cbs);
33
34 // ============================================================================
35 // list box control implementation
36 // ============================================================================
37
38 // Listbox item
39 wxListBox::wxListBox(): m_clientDataList(wxKEY_INTEGER)
40 {
41 m_noItems = 0;
42 m_selected = 0;
43 }
44
45 bool wxListBox::Create(wxWindow *parent, wxWindowID id,
46 const wxPoint& pos,
47 const wxSize& size,
48 int n, const wxString choices[],
49 long style,
50 const wxValidator& validator,
51 const wxString& name)
52 {
53 m_windowStyle = style;
54 m_noItems = n;
55 m_selected = 0;
56 // m_backgroundColour = parent->GetBackgroundColour();
57 m_backgroundColour = * wxWHITE;
58 m_foregroundColour = parent->GetForegroundColour();
59
60 SetName(name);
61 SetValidator(validator);
62
63 if (parent) parent->AddChild(this);
64
65 m_windowId = ( id == -1 ) ? (int)NewControlId() : id;
66
67 Widget parentWidget = (Widget) parent->GetClientWidget();
68
69 Arg args[3];
70 int count;
71 XtSetArg (args[0], XmNlistSizePolicy, XmCONSTANT);
72 if (m_windowStyle & wxLB_MULTIPLE)
73 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
74 else if (m_windowStyle & wxLB_EXTENDED)
75 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
76 else
77 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
78 if (m_windowStyle & wxLB_ALWAYS_SB)
79 {
80 XtSetArg (args[2], XmNscrollBarDisplayPolicy, XmSTATIC);
81 count = 3;
82 }
83 else
84 count = 2;
85
86 Widget listWidget = XmCreateScrolledList (parentWidget, (char*) (const char*) name, args, count);
87
88 m_mainWidget = (WXWidget) listWidget;
89
90 Set(n, choices);
91
92 XtManageChild (listWidget);
93
94 long width = size.x;
95 long height = size.y;
96 if (width == -1)
97 width = 150;
98 if (height == -1)
99 height = 80;
100
101 XtAddCallback (listWidget, XmNbrowseSelectionCallback, (XtCallbackProc) wxListBoxCallback,
102 (XtPointer) this);
103 XtAddCallback (listWidget, XmNextendedSelectionCallback, (XtCallbackProc) wxListBoxCallback,
104 (XtPointer) this);
105 XtAddCallback (listWidget, XmNmultipleSelectionCallback, (XtCallbackProc) wxListBoxCallback,
106 (XtPointer) this);
107
108 XtAddCallback (listWidget, XmNdefaultActionCallback, (XtCallbackProc) wxListBoxDefaultActionProc,
109 (XtPointer) this);
110
111 m_windowFont = parent->GetFont();
112 ChangeFont(FALSE);
113
114 SetCanAddEventHandler(TRUE);
115 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, width, height);
116
117 ChangeBackgroundColour();
118
119 return TRUE;
120 }
121
122 wxListBox::~wxListBox()
123 {
124 }
125
126 void wxListBox::SetFirstItem(int N)
127 {
128 int count, length;
129
130 if (N < 0)
131 return;
132 XtVaGetValues ((Widget) m_mainWidget,
133 XmNvisibleItemCount, &count,
134 XmNitemCount, &length,
135 NULL);
136 if ((N + count) >= length)
137 N = length - count;
138 XmListSetPos ((Widget) m_mainWidget, N + 1);
139 }
140
141 void wxListBox::SetFirstItem(const wxString& s)
142 {
143 int N = FindString (s);
144
145 if (N >= 0)
146 SetFirstItem (N);
147 }
148
149 void wxListBox::Delete(int N)
150 {
151 int width1, height1;
152 int width2, height2;
153 Widget listBox = (Widget) m_mainWidget;
154 GetSize (&width1, &height1);
155
156 bool managed = XtIsManaged(listBox);
157
158 if (managed)
159 XtUnmanageChild (listBox);
160
161 XmListDeletePos (listBox, N + 1);
162
163 if (managed)
164 XtManageChild (listBox);
165
166 GetSize (&width2, &height2);
167 // Correct for randomly resized listbox - bad boy, Motif!
168 if (width1 != width2 || height1 != height2)
169 SetSize (-1, -1, width1, height1);
170
171 // (JDH) need to add code here to take care of clientDataList
172 wxNode *node = m_clientDataList.Find((long)N); // get item from list
173 if (node) m_clientDataList.DeleteNode(node); // if existed then delete from list
174 node = m_clientDataList.First(); // we now have to adjust all keys that
175 while (node) // are >=N+1
176 { if (node->GetKeyInteger() >= (long)(N+1))
177 node->SetKeyInteger(node->GetKeyInteger() - 1);
178 node = node->Next();
179 }
180
181 m_noItems --;
182 }
183
184 void wxListBox::Append(const wxString& item)
185 {
186 int width1, height1;
187 int width2, height2;
188
189 Widget listBox = (Widget) m_mainWidget;
190 GetSize (&width1, &height1);
191
192 bool managed = XtIsManaged(listBox);
193
194 if (managed)
195 XtUnmanageChild (listBox);
196 int n;
197 XtVaGetValues (listBox, XmNitemCount, &n, NULL);
198 XmString text = XmStringCreateSimple ((char*) (const char*) item);
199 // XmListAddItem(listBox, text, n + 1);
200 XmListAddItemUnselected (listBox, text, 0);
201 XmStringFree (text);
202
203 // It seems that if the list is cleared, we must re-ask for
204 // selection policy!!
205 Arg args[3];
206 XtSetArg (args[0], XmNlistSizePolicy, XmCONSTANT);
207 if (m_windowStyle & wxLB_MULTIPLE)
208 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
209 else if (m_windowStyle & wxLB_EXTENDED)
210 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
211 else
212 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
213 XtSetValues (listBox, args, 2);
214
215 if (managed)
216 XtManageChild (listBox);
217
218 GetSize (&width2, &height2);
219 // Correct for randomly resized listbox - bad boy, Motif!
220 if (width1 != width2 || height1 != height2)
221 SetSize (-1, -1, width1, height1);
222 m_noItems ++;
223 }
224
225 void wxListBox::Append(const wxString& item, char *clientData)
226 {
227 int width1, height1;
228 int width2, height2;
229
230 Widget listBox = (Widget) m_mainWidget;
231
232 GetSize (&width1, &height1);
233 Bool managed = XtIsManaged(listBox);
234
235 if (managed)
236 XtUnmanageChild (listBox);
237
238 int n;
239 XtVaGetValues (listBox, XmNitemCount, &n, NULL);
240 XmString text = XmStringCreateSimple ((char*) (const char*) item);
241 // XmListAddItem(listBox, text, n + 1);
242 XmListAddItemUnselected (listBox, text, 0);
243 XmStringFree (text);
244
245 // It seems that if the list is cleared, we must re-ask for
246 // selection policy!!
247 Arg args[3];
248 XtSetArg (args[0], XmNlistSizePolicy, XmCONSTANT);
249 if (m_windowStyle & wxLB_MULTIPLE)
250 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
251 else if (m_windowStyle & wxLB_EXTENDED)
252 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
253 else
254 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
255 XtSetValues (listBox, args, 2);
256
257 m_clientDataList.Append ((long) n, (wxObject *) clientData);
258
259 if (managed)
260 XtManageChild (listBox);
261
262 GetSize (&width2, &height2);
263
264 // Correct for randomly resized listbox - bad boy, Motif!
265 if (width1 != width2 || height1 != height2)
266 SetSize (-1, -1, width1, height1);
267
268 m_noItems ++;
269 }
270
271 void wxListBox::Set(int n, const wxString *choices, char** clientData)
272 {
273 m_clientDataList.Clear();
274 int width1, height1;
275 int width2, height2;
276
277 Widget listBox = (Widget) m_mainWidget;
278 GetSize (&width1, &height1);
279
280 bool managed = XtIsManaged(listBox);
281
282 if (managed)
283 XtUnmanageChild (listBox);
284 /***
285 for (int i=0; i<n; i++)
286 {
287 XmString text = XmStringCreateSimple(choices[i]);
288 XmListAddItemUnselected(listBox, text, 0);
289 XmStringFree(text);
290 }
291 ***/
292 XmString *text = new XmString[n];
293 int i;
294 for (i = 0; i < n; i++)
295 text[i] = XmStringCreateSimple ((char*) (const char*) choices[i]);
296
297 if ( clientData )
298 for (i = 0; i < n; i++)
299 m_clientDataList.Append ((long) i, (wxObject *) clientData[i]);
300
301 XmListAddItems (listBox, text, n, 0);
302 for (i = 0; i < n; i++)
303 XmStringFree (text[i]);
304 delete[]text;
305
306 // It seems that if the list is cleared, we must re-ask for
307 // selection policy!!
308 Arg args[3];
309 XtSetArg (args[0], XmNlistSizePolicy, XmCONSTANT);
310 if (m_windowStyle & wxLB_MULTIPLE)
311 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
312 else if (m_windowStyle & wxLB_EXTENDED)
313 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
314 else
315 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
316 XtSetValues (listBox, args, 2);
317
318 if (managed)
319 XtManageChild (listBox);
320
321 GetSize (&width2, &height2);
322 // Correct for randomly resized listbox - bad boy, Motif!
323 if (width1 != width2 || height1 != height2)
324 SetSize (-1, -1, width1, height1);
325
326 m_noItems = n;
327 }
328
329 int wxListBox::FindString(const wxString& s) const
330 {
331 XmString str = XmStringCreateSimple ((char*) (const char*) s);
332 int *positions = NULL;
333 int no_positions = 0;
334 bool success = XmListGetMatchPos ((Widget) m_mainWidget, str, &positions, &no_positions);
335 XmStringFree (str);
336 if (success)
337 {
338 int pos = positions[0];
339 if (positions)
340 XtFree ((char *) positions);
341 return pos - 1;
342 }
343 else
344 return -1;
345 }
346
347 void wxListBox::Clear()
348 {
349 if (m_noItems <= 0)
350 return;
351
352 int width1, height1;
353 int width2, height2;
354
355 Widget listBox = (Widget) m_mainWidget;
356 GetSize (&width1, &height1);
357
358 XmListDeleteAllItems (listBox);
359 m_clientDataList.Clear ();
360 GetSize (&width2, &height2);
361
362 // Correct for randomly resized listbox - bad boy, Motif!
363 if (width1 != width2 || height1 != height2)
364 SetSize (-1, -1, width1, height1);
365
366 m_noItems = 0;
367 }
368
369 void wxListBox::SetSelection(int N, bool select)
370 {
371 m_inSetValue = TRUE;
372 if (select)
373 {
374 /*
375 if (m_windowStyle & wxLB_MULTIPLE)
376 {
377 int *selections = NULL;
378 int n = GetSelections (&selections);
379
380 // This hack is supposed to work, to make it possible to select more
381 // than one item, but it DOESN'T under Motif 1.1.
382
383 XtVaSetValues ((Widget) m_mainWidget, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
384
385 int i;
386 for (i = 0; i < n; i++)
387 XmListSelectPos ((Widget) m_mainWidget, selections[i] + 1, FALSE);
388
389 XmListSelectPos ((Widget) m_mainWidget, N + 1, FALSE);
390
391 XtVaSetValues ((Widget) m_mainWidget, XmNselectionPolicy, XmEXTENDED_SELECT, NULL);
392 }
393 else
394 */
395 XmListSelectPos ((Widget) m_mainWidget, N + 1, FALSE);
396
397 }
398 else
399 XmListDeselectPos ((Widget) m_mainWidget, N + 1);
400
401 m_inSetValue = FALSE;
402 }
403
404 bool wxListBox::Selected(int N) const
405 {
406 // In Motif, no simple way to determine if the item is selected.
407 wxArrayInt theSelections;
408 int count = GetSelections (theSelections);
409 if (count == 0)
410 return FALSE;
411 else
412 {
413 int j;
414 for (j = 0; j < count; j++)
415 if (theSelections[j] == N)
416 return TRUE;
417 }
418 return FALSE;
419 }
420
421 void wxListBox::Deselect(int N)
422 {
423 XmListDeselectPos ((Widget) m_mainWidget, N + 1);
424 }
425
426 char *wxListBox::GetClientData(int N) const
427 {
428 wxNode *node = m_clientDataList.Find ((long) N);
429 if (node)
430 return (char *) node->Data ();
431 else
432 return NULL;
433 }
434
435 void wxListBox::SetClientData(int N, char *Client_data)
436 {
437 wxNode *node = m_clientDataList.Find ((long) N);
438 if (node)
439 node->SetData ((wxObject *)Client_data);
440 else
441 node = m_clientDataList.Append((long) N, (wxObject*) Client_data);
442 }
443
444 // Return number of selections and an array of selected integers
445 int wxListBox::GetSelections(wxArrayInt& aSelections) const
446 {
447 aSelections.Empty();
448
449 Widget listBox = (Widget) m_mainWidget;
450 int *posList = NULL;
451 int posCnt = 0;
452 bool flag = XmListGetSelectedPos (listBox, &posList, &posCnt);
453 if (flag)
454 {
455 if (posCnt > 0)
456 {
457 aSelections.Alloc(posCnt);
458
459 int i;
460 for (i = 0; i < posCnt; i++)
461 aSelections.Add(posList[i] - 1);
462
463 XtFree ((char *) posList);
464 return posCnt;
465 }
466 else
467 return 0;
468 }
469 else
470 return 0;
471 }
472
473 // Get single selection, for single choice list items
474 int wxListBox::GetSelection() const
475 {
476 Widget listBox = (Widget) m_mainWidget;
477 int *posList = NULL;
478 int posCnt = 0;
479 bool flag = XmListGetSelectedPos (listBox, &posList, &posCnt);
480 if (flag)
481 {
482 int id = -1;
483 if (posCnt > 0)
484 id = posList[0] - 1;
485 XtFree ((char *) posList);
486 return id;
487 }
488 else
489 return -1;
490 }
491
492 // Find string for position
493 wxString wxListBox::GetString(int N) const
494 {
495 Widget listBox = (Widget) m_mainWidget;
496 XmString *strlist;
497 int n;
498 XtVaGetValues (listBox, XmNitemCount, &n, XmNitems, &strlist, NULL);
499 if (N <= n && N >= 0)
500 {
501 char *txt;
502 if (XmStringGetLtoR (strlist[N], XmSTRING_DEFAULT_CHARSET, &txt))
503 {
504 wxString str(txt);
505 XtFree (txt);
506 return str;
507 }
508 else
509 return wxEmptyString;
510 }
511 else
512 return wxEmptyString;
513 }
514
515 void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags)
516 {
517 wxWindow::SetSize(x, y, width, height, sizeFlags);
518
519 // Check resulting size is correct
520 int tempW, tempH;
521 GetSize (&tempW, &tempH);
522
523 /*
524 if (tempW != width || tempH != height)
525 {
526 cout << "wxListBox::SetSize sizes not set correctly.");
527 }
528 */
529 }
530
531 void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
532 {
533 int width1, height1;
534 int width2, height2;
535
536 Widget listBox = (Widget) m_mainWidget;
537
538 GetSize(&width1, &height1);
539
540 bool managed = XtIsManaged(listBox);
541
542 if (managed)
543 XtUnmanageChild(listBox);
544
545 XmString *text = new XmString[nItems];
546 int i;
547 // Steve Hammes: Motif 1.1 compatibility
548 // #if XmVersion > 1100
549 // Corrected by Sergey Krasnov from Steve Hammes' code
550 #if XmVersion > 1001
551 for (i = 0; i < nItems; i++)
552 text[i] = XmStringCreateSimple((char*) (const char*) items[i]);
553 XmListAddItemsUnselected(listBox, text, nItems, pos+1);
554 #else
555 for (i = 0; i < nItems; i++)
556 {
557 text[i] = XmStringCreateSimple((char*) (const char*) items[i]);
558 // XmListAddItemUnselected(listBox, text[i], i);
559 XmListAddItemUnselected(listBox, text[i], pos+i+1); // Another Sergey correction
560 }
561 #endif
562 for (i = 0; i < nItems; i++)
563 XmStringFree(text[i]);
564
565 delete[] text;
566
567 // It seems that if the list is cleared, we must re-ask for
568 // selection policy!!
569 Arg args[3];
570 XtSetArg(args[0], XmNlistSizePolicy, XmCONSTANT);
571 if (m_windowStyle & wxLB_MULTIPLE)
572 XtSetArg(args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
573 else if (m_windowStyle & wxLB_EXTENDED)
574 XtSetArg(args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
575 else XtSetArg(args[1], XmNselectionPolicy, XmBROWSE_SELECT);
576 XtSetValues(listBox,args,2) ;
577
578 if (managed)
579 XtManageChild(listBox);
580
581 GetSize(&width2, &height2);
582 // Correct for randomly resized listbox - bad boy, Motif!
583 if (width1 != width2 /*|| height1 != height2*/)
584 SetSize(-1, -1, width1, height1);
585
586 m_noItems += nItems;
587 }
588
589 void wxListBox::SetString(int N, const wxString& s)
590 {
591 int width1, height1;
592 int width2, height2;
593
594 Widget listBox = (Widget) m_mainWidget;
595 GetSize (&width1, &height1);
596
597 XmString text = XmStringCreateSimple ((char*) (const char*) s);
598
599 // WHAT'S THE MOTIF CALL TO SET THE TEXT OF AN EXISTING
600 // ITEM???
601 // There isn't one, so delete the item and add it again.
602 XmListDeletePos (listBox, N+1);
603 XmListAddItem (listBox, text, N+1);
604
605 XmStringFree(text);
606
607 /*
608 // It seems that if the list is cleared, we must re-ask for
609 // selection policy!!
610 Arg args[3];
611 XtSetArg (args[0], XmNlistSizePolicy, XmCONSTANT);
612 if (m_windowStyle & wxLB_MULTIPLE)
613 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
614 else if (m_windowStyle & wxLB_EXTENDED)
615 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
616 else
617 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
618 XtSetValues (listBox, args, 2);
619 */
620
621 GetSize (&width2, &height2);
622 // Correct for randomly resized listbox - bad boy, Motif!
623 if (width1 != width2 || height1 != height2)
624 SetSize (-1, -1, width1, height1);
625 }
626
627 int wxListBox::Number () const
628 {
629 return m_noItems;
630 }
631
632 // For single selection items only
633 wxString wxListBox::GetStringSelection () const
634 {
635 int sel = GetSelection ();
636 if (sel > -1)
637 return this->GetString (sel);
638 else
639 return wxString("");
640 }
641
642 bool wxListBox::SetStringSelection (const wxString& s, bool flag)
643 {
644 int sel = FindString (s);
645 if (sel > -1)
646 {
647 SetSelection (sel, flag);
648 return TRUE;
649 }
650 else
651 return FALSE;
652 }
653
654 void wxListBox::Command (wxCommandEvent & event)
655 {
656 if (event.m_extraLong)
657 SetSelection (event.m_commandInt);
658 else
659 {
660 Deselect (event.m_commandInt);
661 return;
662 }
663 ProcessCommand (event);
664 }
665
666 void wxListBoxCallback (Widget w, XtPointer clientData,
667 XmListCallbackStruct * cbs)
668 {
669 /*
670 if (cbs->reason == XmCR_EXTENDED_SELECT)
671 cout << "*** Extend select\n";
672 else if (cbs->reason == XmCR_SINGLE_SELECT)
673 cout << "*** Single select\n";
674 else if (cbs->reason == XmCR_MULTIPLE_SELECT)
675 cout << "*** Multiple select\n";
676 else if (cbs->reason == XmCR_BROWSE_SELECT)
677 cout << "*** Browse select\n";
678
679 if (cbs->selection_type == XmMODIFICATION)
680 cout << "*** Modification\n";
681 else if (cbs->selection_type == XmINITIAL)
682 cout << "*** Initial\n";
683 else if (cbs->selection_type == XmADDITION)
684 cout << "*** Addition\n";
685 */
686
687 wxListBox *item = (wxListBox *) clientData;
688
689 if (item->InSetValue())
690 return;
691
692 wxCommandEvent event (wxEVT_COMMAND_LISTBOX_SELECTED, item->GetId());
693 switch (cbs->reason)
694 {
695 case XmCR_MULTIPLE_SELECT:
696 case XmCR_BROWSE_SELECT:
697 {
698 event.m_clientData = item->GetClientData (cbs->item_position - 1);
699 //event.commandString = item->GetStringSelection();
700 event.m_commandInt = cbs->item_position - 1;
701 event.m_extraLong = TRUE;
702 event.SetEventObject(item);
703 item->ProcessCommand (event);
704 //delete[] event.commandString; // Let's not store the command string any more
705 break;
706 }
707 case XmCR_EXTENDED_SELECT:
708 {
709 switch (cbs->selection_type)
710 {
711 case XmINITIAL:
712 case XmADDITION:
713 case XmMODIFICATION:
714 {
715 event.m_clientData = item->GetClientData (cbs->item_position - 1);
716 event.m_commandInt = cbs->item_position - 1;
717 event.m_extraLong = TRUE;
718 event.SetEventObject(item);
719 item->ProcessCommand (event);
720 break;
721 }
722 }
723 break;
724 }
725 }
726 }
727
728 /* Respond by getting the
729 * designated "default button" in the action area and activate it
730 * as if the user had selected it.
731 */
732 void wxListBoxDefaultActionProc (Widget list_w, XtPointer client_data, XmListCallbackStruct * cbs)
733 {
734 wxListBox *lbox = (wxListBox *) client_data;
735
736 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, lbox->GetId());
737 event.SetEventObject( lbox );
738 lbox->GetEventHandler()->ProcessEvent(event) ;
739 }
740
741 WXWidget wxListBox::GetTopWidget() const
742 {
743 return (WXWidget) XtParent( (Widget) m_mainWidget );
744 }
745
746 void wxListBox::ChangeFont(bool keepOriginalSize)
747 {
748 wxWindow::ChangeFont(keepOriginalSize);
749 }
750
751 void wxListBox::ChangeBackgroundColour()
752 {
753 wxWindow::ChangeBackgroundColour();
754
755 Widget parent = XtParent ((Widget) m_mainWidget);
756 Widget hsb, vsb;
757
758 XtVaGetValues (parent,
759 XmNhorizontalScrollBar, &hsb,
760 XmNverticalScrollBar, &vsb,
761 NULL);
762
763 /* TODO: should scrollbars be affected? Should probably have separate
764 * function to change them (by default, taken from wxSystemSettings)
765 */
766 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
767 DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
768 DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
769
770 XtVaSetValues (hsb,
771 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(hsb)),
772 NULL);
773 XtVaSetValues (vsb,
774 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(vsb)),
775 NULL);
776
777 DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
778 }
779
780 void wxListBox::ChangeForegroundColour()
781 {
782 wxWindow::ChangeForegroundColour();
783
784 Widget parent = XtParent ((Widget) m_mainWidget);
785 Widget hsb, vsb;
786
787 XtVaGetValues (parent,
788 XmNhorizontalScrollBar, &hsb,
789 XmNverticalScrollBar, &vsb,
790 NULL);
791 /* TODO: should scrollbars be affected? Should probably have separate
792 * function to change them (by default, taken from wxSystemSettings)
793 DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
794 DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
795 DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
796 */
797 }
798
799