]> git.saurik.com Git - wxWidgets.git/blame - src/motif/listbox.cpp
latest CW additions
[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
2d120f83 26IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
4bb6408c
JS
27#endif
28
f97c9854 29void wxListBoxCallback (Widget w, XtPointer clientData,
2d120f83 30 XmListCallbackStruct * cbs);
f97c9854
JS
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;
94b49b93
JS
56 // m_backgroundColour = parent->GetBackgroundColour();
57 m_backgroundColour = * wxWHITE;
0d57be45 58 m_foregroundColour = parent->GetForegroundColour();
2d120f83 59
f97c9854
JS
60 SetName(name);
61 SetValidator(validator);
2d120f83 62
f97c9854 63 if (parent) parent->AddChild(this);
2d120f83 64
f97c9854 65 m_windowId = ( id == -1 ) ? (int)NewControlId() : id;
2d120f83 66
f97c9854 67 Widget parentWidget = (Widget) parent->GetClientWidget();
2d120f83 68
f97c9854
JS
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;
2d120f83 85
f97c9854 86 Widget listWidget = XmCreateScrolledList (parentWidget, (char*) (const char*) name, args, count);
2d120f83 87
f97c9854 88 m_mainWidget = (WXWidget) listWidget;
2d120f83 89
a4294b78 90 Set(n, choices);
2d120f83 91
f97c9854 92 XtManageChild (listWidget);
2d120f83 93
f97c9854
JS
94 long width = size.x;
95 long height = size.y;
96 if (width == -1)
97 width = 150;
98 if (height == -1)
99 height = 80;
2d120f83 100
f97c9854 101 XtAddCallback (listWidget, XmNbrowseSelectionCallback, (XtCallbackProc) wxListBoxCallback,
2d120f83 102 (XtPointer) this);
f97c9854 103 XtAddCallback (listWidget, XmNextendedSelectionCallback, (XtCallbackProc) wxListBoxCallback,
2d120f83 104 (XtPointer) this);
f97c9854 105 XtAddCallback (listWidget, XmNmultipleSelectionCallback, (XtCallbackProc) wxListBoxCallback,
2d120f83
JS
106 (XtPointer) this);
107
f97c9854 108 XtAddCallback (listWidget, XmNdefaultActionCallback, (XtCallbackProc) wxListBoxDefaultActionProc,
2d120f83
JS
109 (XtPointer) this);
110
4b5f3fe6
JS
111 m_windowFont = parent->GetFont();
112 ChangeFont(FALSE);
2d120f83 113
15d5ab67 114 SetCanAddEventHandler(TRUE);
f97c9854 115 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, width, height);
2d120f83 116
0d57be45 117 ChangeBackgroundColour();
2d120f83 118
f97c9854 119 return TRUE;
4bb6408c
JS
120}
121
122wxListBox::~wxListBox()
123{
124}
125
126void wxListBox::SetFirstItem(int N)
127{
2d120f83
JS
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);
4bb6408c
JS
139}
140
141void wxListBox::SetFirstItem(const wxString& s)
142{
2d120f83
JS
143 int N = FindString (s);
144
145 if (N >= 0)
146 SetFirstItem (N);
4bb6408c
JS
147}
148
149void wxListBox::Delete(int N)
150{
2d120f83
JS
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 --;
4bb6408c
JS
182}
183
184void wxListBox::Append(const wxString& item)
185{
2d120f83
JS
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 ++;
4bb6408c
JS
223}
224
f97c9854 225void wxListBox::Append(const wxString& item, char *clientData)
4bb6408c 226{
2d120f83
JS
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 ++;
4bb6408c
JS
269}
270
271void wxListBox::Set(int n, const wxString *choices, char** clientData)
272{
2d120f83
JS
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;
f97c9854 294 for (i = 0; i < n; i++)
2d120f83
JS
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;
4bb6408c
JS
327}
328
329int wxListBox::FindString(const wxString& s) const
330{
2d120f83
JS
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)
f97c9854 337 {
2d120f83
JS
338 int pos = positions[0];
339 if (positions)
340 XtFree ((char *) positions);
341 return pos - 1;
f97c9854 342 }
2d120f83
JS
343 else
344 return -1;
4bb6408c
JS
345}
346
347void wxListBox::Clear()
348{
2d120f83
JS
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;
4bb6408c
JS
367}
368
369void wxListBox::SetSelection(int N, bool select)
370{
2d120f83
JS
371 m_inSetValue = TRUE;
372 if (select)
f97c9854 373 {
2d120f83
JS
374 /*
375 if (m_windowStyle & wxLB_MULTIPLE)
f97c9854 376 {
2d120f83
JS
377 int *selections = NULL;
378 int n = GetSelections (&selections);
379
f97c9854
JS
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.
2d120f83
JS
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
f97c9854 397 }
2d120f83
JS
398 else
399 XmListDeselectPos ((Widget) m_mainWidget, N + 1);
400
401 m_inSetValue = FALSE;
4bb6408c
JS
402}
403
404bool wxListBox::Selected(int N) const
405{
2d120f83
JS
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 }
4bb6408c
JS
418 return FALSE;
419}
420
421void wxListBox::Deselect(int N)
422{
f97c9854 423 XmListDeselectPos ((Widget) m_mainWidget, N + 1);
4bb6408c
JS
424}
425
426char *wxListBox::GetClientData(int N) const
427{
f97c9854
JS
428 wxNode *node = m_clientDataList.Find ((long) N);
429 if (node)
430 return (char *) node->Data ();
431 else
432 return NULL;
4bb6408c
JS
433}
434
435void wxListBox::SetClientData(int N, char *Client_data)
436{
f97c9854
JS
437 wxNode *node = m_clientDataList.Find ((long) N);
438 if (node)
439 node->SetData ((wxObject *)Client_data);
a4294b78
JS
440 else
441 node = m_clientDataList.Append((long) N, (wxObject*) Client_data);
4bb6408c
JS
442}
443
444// Return number of selections and an array of selected integers
445int wxListBox::GetSelections(wxArrayInt& aSelections) const
446{
2d120f83
JS
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;
4bb6408c 468 }
2d120f83
JS
469 else
470 return 0;
4bb6408c
JS
471}
472
473// Get single selection, for single choice list items
474int wxListBox::GetSelection() const
475{
f97c9854
JS
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;
4bb6408c
JS
490}
491
492// Find string for position
493wxString wxListBox::GetString(int N) const
494{
f97c9854
JS
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;
4bb6408c
JS
513}
514
515void wxListBox::SetSize(int x, int y, int width, int height, int sizeFlags)
516{
f97c9854 517 wxWindow::SetSize(x, y, width, height, sizeFlags);
2d120f83 518
f97c9854
JS
519 // Check resulting size is correct
520 int tempW, tempH;
521 GetSize (&tempW, &tempH);
2d120f83 522
89c7e962
JS
523 /*
524 if (tempW != width || tempH != height)
525 {
2d120f83 526 cout << "wxListBox::SetSize sizes not set correctly.");
89c7e962
JS
527 }
528 */
4bb6408c
JS
529}
530
531void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
532{
f97c9854
JS
533 int width1, height1;
534 int width2, height2;
2d120f83 535
f97c9854 536 Widget listBox = (Widget) m_mainWidget;
2d120f83 537
f97c9854 538 GetSize(&width1, &height1);
2d120f83 539
f97c9854 540 bool managed = XtIsManaged(listBox);
2d120f83 541
f97c9854
JS
542 if (managed)
543 XtUnmanageChild(listBox);
2d120f83 544
f97c9854
JS
545 XmString *text = new XmString[nItems];
546 int i;
2d120f83
JS
547 // Steve Hammes: Motif 1.1 compatibility
548 // #if XmVersion > 1100
549 // Corrected by Sergey Krasnov from Steve Hammes' code
f97c9854
JS
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]);
2d120f83 558 // XmListAddItemUnselected(listBox, text[i], i);
f97c9854
JS
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]);
2d120f83 564
f97c9854 565 delete[] text;
2d120f83 566
f97c9854
JS
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) ;
2d120f83 577
f97c9854
JS
578 if (managed)
579 XtManageChild(listBox);
2d120f83 580
f97c9854
JS
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);
2d120f83 585
f97c9854 586 m_noItems += nItems;
4bb6408c
JS
587}
588
589void wxListBox::SetString(int N, const wxString& s)
590{
f97c9854
JS
591 int width1, height1;
592 int width2, height2;
2d120f83 593
f97c9854
JS
594 Widget listBox = (Widget) m_mainWidget;
595 GetSize (&width1, &height1);
2d120f83 596
f97c9854 597 XmString text = XmStringCreateSimple ((char*) (const char*) s);
2d120f83 598
f97c9854
JS
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);
2d120f83 604
f97c9854 605 XmStringFree(text);
2d120f83
JS
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)
f97c9854 613 XtSetArg (args[1], XmNselectionPolicy, XmMULTIPLE_SELECT);
2d120f83 614 else if (m_windowStyle & wxLB_EXTENDED)
f97c9854 615 XtSetArg (args[1], XmNselectionPolicy, XmEXTENDED_SELECT);
2d120f83 616 else
f97c9854 617 XtSetArg (args[1], XmNselectionPolicy, XmBROWSE_SELECT);
2d120f83
JS
618 XtSetValues (listBox, args, 2);
619 */
620
f97c9854
JS
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);
4bb6408c
JS
625}
626
627int wxListBox::Number () const
628{
f97c9854 629 return m_noItems;
4bb6408c
JS
630}
631
632// For single selection items only
633wxString wxListBox::GetStringSelection () const
634{
f97c9854
JS
635 int sel = GetSelection ();
636 if (sel > -1)
637 return this->GetString (sel);
638 else
639 return wxString("");
4bb6408c
JS
640}
641
642bool wxListBox::SetStringSelection (const wxString& s, bool flag)
643{
f97c9854
JS
644 int sel = FindString (s);
645 if (sel > -1)
4bb6408c 646 {
f97c9854
JS
647 SetSelection (sel, flag);
648 return TRUE;
4bb6408c 649 }
f97c9854
JS
650 else
651 return FALSE;
4bb6408c
JS
652}
653
654void wxListBox::Command (wxCommandEvent & event)
655{
f97c9854
JS
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
666void wxListBoxCallback (Widget w, XtPointer clientData,
2d120f83 667 XmListCallbackStruct * cbs)
f97c9854
JS
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";
2d120f83
JS
685 */
686
f97c9854 687 wxListBox *item = (wxListBox *) clientData;
2d120f83 688
a4294b78 689 if (item->InSetValue())
f97c9854 690 return;
2d120f83 691
b412f9be 692 wxCommandEvent event (wxEVT_COMMAND_LISTBOX_SELECTED, item->GetId());
f97c9854 693 switch (cbs->reason)
4bb6408c 694 {
2d120f83
JS
695 case XmCR_MULTIPLE_SELECT:
696 case XmCR_BROWSE_SELECT:
f97c9854
JS
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 }
2d120f83 707 case XmCR_EXTENDED_SELECT:
f97c9854
JS
708 {
709 switch (cbs->selection_type)
710 {
2d120f83
JS
711 case XmINITIAL:
712 case XmADDITION:
713 case XmMODIFICATION:
f97c9854
JS
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 }
4bb6408c 725 }
4bb6408c
JS
726}
727
f97c9854 728/* Respond by getting the
2d120f83
JS
729* designated "default button" in the action area and activate it
730* as if the user had selected it.
731*/
f97c9854
JS
732void wxListBoxDefaultActionProc (Widget list_w, XtPointer client_data, XmListCallbackStruct * cbs)
733{
734 wxListBox *lbox = (wxListBox *) client_data;
2d120f83 735
f97c9854
JS
736 wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, lbox->GetId());
737 event.SetEventObject( lbox );
738 lbox->GetEventHandler()->ProcessEvent(event) ;
739}
740
89c7e962
JS
741WXWidget wxListBox::GetTopWidget() const
742{
2d120f83 743 return (WXWidget) XtParent( (Widget) m_mainWidget );
89c7e962 744}
0d57be45 745
4b5f3fe6 746void wxListBox::ChangeFont(bool keepOriginalSize)
0d57be45 747{
4b5f3fe6 748 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
749}
750
751void wxListBox::ChangeBackgroundColour()
752{
321db4b6 753 wxWindow::ChangeBackgroundColour();
2d120f83 754
02800301
JS
755 Widget parent = XtParent ((Widget) m_mainWidget);
756 Widget hsb, vsb;
2d120f83 757
02800301 758 XtVaGetValues (parent,
2d120f83
JS
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 */
94b49b93
JS
766 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
767 DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
768 DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
15d5ab67
JS
769
770 XtVaSetValues (hsb,
771 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(hsb)),
772 NULL);
773 XtVaSetValues (vsb,
774 XmNtroughColor, backgroundColour.AllocColour(XtDisplay(vsb)),
775 NULL);
2d120f83 776
02800301 777 DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
0d57be45
JS
778}
779
780void wxListBox::ChangeForegroundColour()
781{
321db4b6 782 wxWindow::ChangeForegroundColour();
2d120f83 783
02800301
JS
784 Widget parent = XtParent ((Widget) m_mainWidget);
785 Widget hsb, vsb;
2d120f83 786
02800301 787 XtVaGetValues (parent,
2d120f83
JS
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);
02800301 796 */
0d57be45
JS
797}
798
02800301 799