~ubuntu-branches/ubuntu/trusty/libcdk5/trusty

« back to all changes in this revision

Viewing changes to selection.c

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2007-06-06 03:54:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070606035431-ba4gdvw0h6ybffsu
Tags: 5.0.20060507-1
* New upstream release.
* Fixed header patching.  Patch from Robert Schiele.
  Closes: #402978, #416336.
* Update widget count in description.  Closes: #294709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <cdk_int.h>
2
2
 
3
3
/*
4
 
 * $Author: Thorsten.Glaser $
5
 
 * $Date: 2005/04/24 20:39:53 $
6
 
 * $Revision: 1.133 $
 
4
 * $Author: tom $
 
5
 * $Date: 2005/12/30 00:29:34 $
 
6
 * $Revision: 1.143 $
7
7
 */
8
8
 
9
9
/*
23
23
                              : (widest - AvailableWidth(w)))
24
24
#define WidestItem(w)      ((w)->maxLeftChar + AvailableWidth(w))
25
25
 
 
26
#define SCREENPOS(w,n) (w)->itemPos[n] - (w)->leftChar + scrollbarAdj /* + BorderOf(w) */
 
27
 
26
28
DeclareCDKObjects(SELECTION, Selection, setCdk, Int);
27
29
 
28
30
/*
127
129
   if (splace == RIGHT)
128
130
   {
129
131
      selection->scrollbarWin = subwin (selection->win,
130
 
                                        maxViewSize(selection), 1,
 
132
                                        maxViewSize(selection), 1,
131
133
                                        SCREEN_YPOS(selection, ypos),
132
 
                                        xpos + selection->boxWidth - BorderOf(selection) - 1);
 
134
                                        xpos + selection->boxWidth - BorderOf(selection) - 1);
133
135
   }
134
136
   else if (splace == LEFT)
135
137
   {
136
138
      selection->scrollbarWin = subwin (selection->win,
137
 
                                        maxViewSize(selection), 1,
 
139
                                        maxViewSize(selection), 1,
138
140
                                        SCREEN_YPOS(selection, ypos),
139
141
                                        SCREEN_XPOS(selection, xpos));
140
142
   }
167
169
 
168
170
   /* Each item in the needs to be converted to chtype * */
169
171
   widestItem = createList(selection, list, listSize);
170
 
   if (widestItem <= 0)
 
172
   if (widestItem > 0)
 
173
   {
 
174
      updateViewWidth(selection, widestItem);
 
175
   }
 
176
   else if (listSize)
171
177
   {
172
178
      destroyCDKObject(selection);
173
179
      return (0);
174
180
   }
175
181
 
176
 
   updateViewWidth(selection, widestItem);
177
 
 
178
182
   /* Do we need to create a shadow. */
179
183
   if (shadow)
180
184
   {
193
197
}
194
198
 
195
199
/*
 
200
 * Put the cursor on the currently-selected item.
 
201
 */
 
202
static void fixCursorPosition (CDKSELECTION *selection)
 
203
{
 
204
   int scrollbarAdj = (selection->scrollbarPlacement == LEFT) ?  1 :  0;
 
205
   int ypos = SCREEN_YPOS(selection, selection->currentItem - selection->currentTop);
 
206
   int xpos = SCREEN_XPOS(selection, 0) + scrollbarAdj;
 
207
 
 
208
   wmove(InputWindowOf(selection), ypos, xpos);
 
209
   wrefresh(InputWindowOf(selection));
 
210
}
 
211
 
 
212
/*
196
213
 * This actually manages the selection widget...
197
214
 */
198
215
int activateCDKSelection (CDKSELECTION *selection, chtype *actions)
200
217
   /* Draw the selection list */
201
218
   drawCDKSelection (selection, ObjOf(selection)->box);
202
219
 
203
 
   /* Check if actions is null. */
204
220
   if (actions == 0)
205
221
   {
206
222
      chtype input;
 
223
      boolean functionKey;
207
224
      int ret;
208
225
 
209
226
      for (;;)
210
227
      {
211
 
         /* Get the input. */
212
 
         input = getcCDKObject (ObjOf(selection));
 
228
         fixCursorPosition (selection);
 
229
         input = getchCDKObject (ObjOf(selection), &functionKey);
213
230
 
214
231
         /* Inject the character into the widget. */
215
232
         ret = injectCDKSelection (selection, input);
369
386
   }
370
387
 
371
388
   ResultOf(selection).valueInt = ret;
 
389
   fixCursorPosition (selection);
372
390
   return (ret != unknownInt);
373
391
}
374
392
 
449
467
   scroller_SetViewSize(widget, listSize);
450
468
}
451
469
 
452
 
#define SCREENPOS(w,n) (w)->itemPos[n] - (w)->leftChar + scrollbarAdj /* + BorderOf(w) */
453
 
 
454
470
/*
455
471
 * This function draws the selection list window.
456
472
 */
460
476
   int screenPos        = 0;
461
477
   int xpos, ypos;
462
478
   int j;
 
479
   int selItem      = -1;
 
480
 
 
481
   /* If there is to be a highlight, assign it now */
 
482
   if (ObjOf(selection)->hasFocus)
 
483
      selItem = selection->currentItem;
463
484
 
464
485
   /* draw the list... */
465
486
   for (j = 0; j < selection->viewSize; j++)
476
497
                   getmaxx(selection->win));
477
498
 
478
499
      /* Draw the selection item. */
479
 
      writeChtype (selection->win,
 
500
      writeChtypeAttrib (selection->win,
480
501
                   (screenPos >= 0) ? screenPos : 1,
481
502
                   ypos,
482
503
                   selection->item[j + selection->currentTop],
 
504
                   ((j + selection->currentTop == selItem)
 
505
                     ? selection->highlight
 
506
                     : A_NORMAL),
483
507
                   HORIZONTAL,
484
508
                   (screenPos >= 0) ? 0 : (1 - screenPos),
485
509
                   selection->itemLen[j + selection->currentTop]);
494
518
                   selection->choicelen[selection->selections[j + selection->currentTop]]);
495
519
   }
496
520
 
497
 
   /* Draw in the current highlight. */
498
 
   if (ObjOf(selection)->hasFocus)
499
 
   {
500
 
      screenPos = SCREENPOS(selection, selection->currentItem);
501
 
      ypos = SCREEN_YPOS(selection, selection->currentHigh);
502
 
 
503
 
      writeChtypeAttrib (selection->win,
504
 
                        (screenPos >= 0) ? screenPos : 1,
505
 
                        ypos,
506
 
                        selection->item[selection->currentItem],
507
 
                        selection->highlight,
508
 
                        HORIZONTAL,
509
 
                        selection->leftChar,
510
 
                        selection->itemLen[selection->currentItem]);
511
 
   }
512
 
 
513
521
   /* Determine where the toggle is supposed to be. */
514
522
   if (selection->scrollbar)
515
523
   {
526
534
      drawObjBox (selection->win, ObjOf(selection));
527
535
   }
528
536
 
529
 
   /* Refresh the window. */
530
 
   refreshCDKWindow (selection->win);
 
537
   fixCursorPosition (selection);
531
538
}
532
539
 
533
540
/*
547
554
   }
548
555
}
549
556
 
 
557
static void destroyInfo (CDKSELECTION *widget)
 
558
{
 
559
   CDKfreeChtypes (widget->item);
 
560
   widget->item = 0;
 
561
 
 
562
   freeAndNull (widget->itemPos);
 
563
   freeAndNull (widget->itemLen);
 
564
   freeAndNull (widget->selections);
 
565
   freeAndNull (widget->mode);
 
566
}
 
567
 
550
568
/*
551
569
 * This function destroys the selection list.
552
570
 */
559
577
      cleanCdkTitle (object);
560
578
      CDKfreeChtypes (selection->choice);
561
579
      freeChecked (selection->choicelen);
562
 
      CDKfreeChtypes (selection->item);
563
 
      freeChecked (selection->itemPos);
564
 
      freeChecked (selection->itemLen);
565
 
      freeChecked (selection->selections);
566
 
      freeChecked (selection->mode);
 
580
      destroyInfo (selection);
567
581
 
568
582
      /* Clean up the windows. */
569
583
      deleteCursesWindow (selection->scrollbarWin);
570
584
      deleteCursesWindow (selection->shadowWin);
571
585
      deleteCursesWindow (selection->win);
572
586
 
 
587
      /* Clean the key bindings. */
 
588
      cleanCDKObjectBindings (vSELECTION, selection);
 
589
 
573
590
      /* Unregister this object. */
574
591
      unregisterCDKObject (vSELECTION, selection);
575
592
   }
592
609
/*
593
610
 * This function sets a couple of the selection list attributes.
594
611
 */
595
 
void setCDKSelection (CDKSELECTION *selection, chtype highlight, int choices[], boolean Box)
 
612
void setCDKSelection (CDKSELECTION *selection, chtype highlight, int * choices, boolean Box)
596
613
{
597
614
   setCDKSelectionChoices (selection, choices);
598
615
   setCDKSelectionHighlight(selection, highlight);
625
642
 
626
643
   updateViewWidth(selection, widestItem);
627
644
}
628
 
int getCDKSelectionItems (CDKSELECTION *selection, char *list[])
 
645
int getCDKSelectionItems (CDKSELECTION *selection, char **list)
629
646
{
630
647
   int j;
631
648
 
632
 
   for (j = 0; j < selection->listSize; j++)
 
649
   if (list != 0)
633
650
   {
634
 
      list[j] = chtype2Char (selection->item[j]);
 
651
      for (j = 0; j < selection->listSize; j++)
 
652
      {
 
653
         list[j] = chtype2Char (selection->item[j]);
 
654
      }
635
655
   }
636
656
   return selection->listSize;
637
657
}
653
673
}
654
674
char *getCDKSelectionTitle (CDKSELECTION *selection GCC_UNUSED)
655
675
{
656
 
   /* FIXME: this is not implemented */
657
 
   return ("HELLO");
 
676
   return chtype2Char(*TitleOf(selection));
658
677
}
659
678
 
660
679
/*
672
691
/*
673
692
 * This sets the default choices for the selection list.
674
693
 */
675
 
void setCDKSelectionChoices (CDKSELECTION *selection, int choices[])
 
694
void setCDKSelectionChoices (CDKSELECTION *selection, int * choices)
676
695
{
677
696
   int j;
678
697
 
750
769
 * This sets the modes of the items in the selection list. Currently
751
770
 * there are only two: editable=0 and read-only=1
752
771
 */
753
 
void setCDKSelectionModes (CDKSELECTION *selection, int modes[])
 
772
void setCDKSelectionModes (CDKSELECTION *selection, int * modes)
754
773
{
755
774
   int j;
756
775
 
856
875
   drawCDKSelectionList (selection, ObjOf(selection)->box);
857
876
}
858
877
 
859
 
dummyRefreshData(Selection)
860
 
 
861
 
dummySaveData(Selection)
862
 
 
863
878
static int createList(CDKSELECTION *selection, char **list, int listSize)
864
879
{
865
880
   int status = 0;
898
913
 
899
914
         if (status)
900
915
         {
901
 
            CDKfreeChtypes (selection->item);
902
 
            freeChecked (selection->itemPos);
903
 
            freeChecked (selection->itemLen);
904
 
            freeChecked (selection->selections);
905
 
            freeChecked (selection->mode);
 
916
            destroyInfo (selection);
906
917
 
907
918
            selection->item       = newList;
908
919
            selection->itemPos    = newPos;
920
931
         }
921
932
      }
922
933
   }
 
934
   else
 
935
   {
 
936
      destroyInfo (selection);
 
937
   }
923
938
 
924
939
   return status ? widestItem : 0;
925
940
}
 
941
 
 
942
dummyRefreshData(Selection)
 
943
 
 
944
dummySaveData(Selection)