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