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

« back to all changes in this revision

Viewing changes to radio.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:40:43 $
6
 
 * $Revision: 1.121 $
 
4
 * $Author: tom $
 
5
 * $Date: 2005/12/30 00:29:34 $
 
6
 * $Revision: 1.130 $
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(RADIO, Radio, setCdk, Int);
27
29
 
28
30
/*
102
104
 
103
105
   /* Each item in the needs to be converted to chtype * */
104
106
   widestItem = createList(radio, list, listSize, radio->boxWidth);
105
 
   if (widestItem <= 0)
 
107
   if (widestItem > 0)
 
108
   {
 
109
      updateViewWidth(radio, widestItem);
 
110
   }
 
111
   else if (listSize)
106
112
   {
107
113
      destroyCDKObject(radio);
108
114
      return (0);
109
115
   }
110
116
 
111
 
   updateViewWidth(radio, widestItem);
112
 
 
113
117
   /* Rejustify the x and y positions if we need to. */
114
118
   alignxy (cdkscreen->window, &xpos, &ypos, radio->boxWidth, radio->boxHeight);
115
119
 
183
187
}
184
188
 
185
189
/*
 
190
 * Put the cursor on the currently-selected item.
 
191
 */
 
192
static void fixCursorPosition (CDKRADIO *widget)
 
193
{
 
194
   int scrollbarAdj = (widget->scrollbarPlacement == LEFT) ?  1 :  0;
 
195
   int ypos = SCREEN_YPOS(widget, widget->currentItem - widget->currentTop);
 
196
   int xpos = SCREEN_XPOS(widget, 0) + scrollbarAdj;
 
197
 
 
198
   wmove(InputWindowOf(widget), ypos, xpos);
 
199
   wrefresh(InputWindowOf(widget));
 
200
}
 
201
 
 
202
/*
186
203
 * This actually manages the radio widget.
187
204
 */
188
205
int activateCDKRadio (CDKRADIO *radio, chtype *actions)
190
207
   /* Draw the radio list. */
191
208
   drawCDKRadio (radio, ObjOf(radio)->box);
192
209
 
193
 
   /* Check if actions is null. */
194
210
   if (actions == 0)
195
211
   {
196
212
      chtype input;
 
213
      boolean functionKey;
197
214
      int ret;
198
215
 
199
216
      for (;;)
200
217
      {
201
 
         /* Get the input. */
202
 
         input = getcCDKObject (ObjOf(radio));
 
218
         fixCursorPosition (radio);
 
219
         input = getchCDKObject (ObjOf(radio), &functionKey);
203
220
 
204
221
         /* Inject the character into the widget. */
205
222
         ret = injectCDKRadio (radio, input);
344
361
      setExitType(radio, 0);
345
362
   }
346
363
 
 
364
   fixCursorPosition (radio);
347
365
   ResultOf(radio).valueInt = ret;
348
366
   return (ret != unknownInt);
349
367
}
425
443
   drawCDKRadioList (radio, ObjOf(radio)->box);
426
444
}
427
445
 
428
 
#define SCREENPOS(w,n) (w)->itemPos[n] - (w)->leftChar + scrollbarAdj + BorderOf(w)
429
 
 
430
446
/*
431
447
 * This redraws the radio list.
432
448
 */
496
512
      drawObjBox (radio->win, ObjOf(radio));
497
513
   }
498
514
 
499
 
   /* Refresh the window. */
500
 
   refreshCDKWindow (radio->win);
 
515
   fixCursorPosition (radio);
501
516
}
502
517
 
503
518
/*
517
532
   }
518
533
}
519
534
 
 
535
static void destroyInfo(CDKRADIO *widget)
 
536
{
 
537
   CDKfreeChtypes (widget->item);
 
538
   widget->item = 0;
 
539
 
 
540
   freeAndNull (widget->itemLen);
 
541
   freeAndNull (widget->itemPos);
 
542
}
 
543
 
520
544
/*
521
545
 * This function destroys the radio widget.
522
546
 */
527
551
      CDKRADIO *radio = (CDKRADIO *)object;
528
552
 
529
553
      cleanCdkTitle (object);
530
 
      CDKfreeChtypes(radio->item);
 
554
      destroyInfo (radio);
531
555
 
532
556
      /* Clean up the windows. */
533
557
      deleteCursesWindow (radio->scrollbarWin);
534
558
      deleteCursesWindow (radio->shadowWin);
535
559
      deleteCursesWindow (radio->win);
536
560
 
 
561
      /* Clean the key bindings. */
 
562
      cleanCDKObjectBindings (vRADIO, radio);
 
563
 
537
564
      /* Unregister this object. */
538
565
      unregisterCDKObject (vRADIO, radio);
539
566
   }
594
621
 
595
622
   updateViewWidth(radio, widestItem);
596
623
}
597
 
int getCDKRadioItems (CDKRADIO *radio, char *list[])
 
624
int getCDKRadioItems (CDKRADIO *radio, char **list)
598
625
{
599
626
   int j;
600
627
 
601
 
   for (j=0; j < radio->listSize; j++)
 
628
   if (list != 0)
602
629
   {
603
 
      list[j] = chtype2Char (radio->item[j]);
 
630
      for (j=0; j < radio->listSize; j++)
 
631
      {
 
632
         list[j] = chtype2Char (radio->item[j]);
 
633
      }
604
634
   }
605
635
   return radio->listSize;
606
636
}
669
699
}
670
700
 
671
701
/*
672
 
 * This sets the current selected item of the widget
 
702
 * This sets the current high lighted item of the widget
673
703
 */
674
704
void setCDKRadioCurrentItem (CDKRADIO *radio, int item)
675
705
{
676
706
   scroller_SetPosition(radio, item);
 
707
   radio->selectedItem = item;
677
708
}
678
709
int getCDKRadioCurrentItem (CDKRADIO *radio)
679
710
{
680
711
   return radio->currentItem;
681
712
}
682
713
 
 
714
/*
 
715
 * This sets the selected item of the widget
 
716
 */
 
717
void setCDKRadioSelectedItem (CDKRADIO *radio, int item)
 
718
{
 
719
   radio->selectedItem = item;
 
720
}
 
721
int getCDKRadioSelectedItem (CDKRADIO *radio)
 
722
{
 
723
   return radio->selectedItem;
 
724
}
 
725
 
683
726
static void _focusCDKRadio(CDKOBJS *object)
684
727
{
685
728
   CDKRADIO *radio = (CDKRADIO *)object;
694
737
   drawCDKRadioList (radio, ObjOf(radio)->box);
695
738
}
696
739
 
697
 
dummyRefreshData(Radio)
698
 
 
699
 
dummySaveData(Radio)
700
 
 
701
740
static int createList (CDKRADIO *radio, char **list, int listSize, int boxWidth)
702
741
{
703
742
   int status = 0;
730
769
         }
731
770
         if (status)
732
771
         {
733
 
            CDKfreeChtypes (radio->item);
734
 
            freeChecked (radio->itemLen);
735
 
            freeChecked (radio->itemPos);
 
772
            destroyInfo (radio);
736
773
 
737
774
            radio->item = newList;
738
775
            radio->itemLen = newLen;
746
783
         }
747
784
      }
748
785
   }
 
786
   else
 
787
   {
 
788
      destroyInfo (radio);
 
789
   }
 
790
 
749
791
   return status ? widestItem : 0;
750
792
}
 
793
 
 
794
dummyRefreshData(Radio)
 
795
 
 
796
dummySaveData(Radio)