Back to index

im-sdk  12.3.91
IIIMLookupChoice.cpp
Go to the documentation of this file.
00001 #include <qpushbutton.h>
00002 #include "IIIMLookupChoice.hh"
00003 
00004 #ifndef MAX
00005 #define MAX(x, y) ((x > y) ? (x) : (y))
00006 #endif
00007 
00008 void
00009 IIIMLookupChoiceItemWidget::drawContents(
00010     QPainter *p
00011 )
00012 {
00013     QRect r = contentsRect();
00014     QSize s1, s2;
00015 
00016     s1 = plabel->draw(p, this, r);
00017     r.moveBy(s1.width() + margin(), 0);
00018     s2 = pchoice->draw(p, this, r);
00019     currentsize = QSize(s1.width() + s2.width() + margin(),
00020                      MAX(s1.height(), s2.height()));
00021     updateGeometry();
00022 }
00023 
00024 QSize
00025 IIIMLookupChoiceItemWidget::sizeHint() const
00026 {
00027     QSize s = minimumSizeHint();
00028     if (s.isValid()) return s;
00029     int plus = (frameWidth() + margin()) * 2 + 1;
00030     return QSize(plus, plus);
00031 }
00032 
00033 QSize
00034 IIIMLookupChoiceItemWidget::minimumSizeHint() const
00035 {
00036     int plus = (frameWidth() + margin()) * 2;
00037     if (!currentsize.isValid()) return currentsize;
00038     return QSize(currentsize.width() + plus, currentsize.height() + plus);
00039 }
00040 
00041 IIIMLookupChoiceItemWidget::
00042 IIIMLookupChoiceItemWidget(
00043     IIIMCF_text label,
00044     IIIMCF_text choice,
00045     QWidget *parent,
00046     const char *name,
00047     WFlags f
00048 ) : QFrame(parent, name, f)
00049 {
00050     plabel = new IIIMText(label);
00051     pchoice = new IIIMText(choice);
00052     setFrameStyle(QFrame::PopupPanel | QFrame::Sunken);
00053     setMargin(1);
00054     setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
00055                            QSizePolicy::Preferred));
00056 }
00057 
00058 IIIMLookupChoiceItemWidget::
00059 ~IIIMLookupChoiceItemWidget()
00060 {
00061     delete plabel;
00062     delete pchoice;
00063 }
00064 
00065 void
00066 IIIMLookupChoiceWidget::erase_all_items()
00067 {
00068     IIIMLookupChoiceItemWidgetList::iterator it;
00069     for (it = itemlist.begin(); it != itemlist.end(); it++) {
00070        delete *it;
00071     }
00072     itemlist.erase(itemlist.begin(), itemlist.end());
00073 }
00074 
00075 void
00076 IIIMLookupChoiceWidget::set_layout(
00077     IIIMCF_lookup_choice ilc
00078 )
00079 {
00080     IIIMF_status st;
00081     int ndir;
00082 
00083     st = iiimcf_get_lookup_choice_configuration(ilc,
00084                                           &choices_per_window,
00085                                           &number_of_rows,
00086                                           &number_of_columns,
00087                                           &ndir);
00088     if (st != IIIMF_STATUS_SUCCESS) return;
00089 #if 0
00090     if ((direction == IIIMCF_LOOKUP_CHOICE_HORIZONTAL_DIRECTION)
00091        && (ndir != direction)) {
00092        playout = new QBoxLayout(this, QBoxLayout::LeftToRight,
00093                              frameWidth(), frameWidth(), name());
00094        playout->setAutoAdd(true);
00095     } else if (!playout || ((direction == IIIMCF_LOOKUP_CHOICE_VERTICAL_DIRECTION)
00096                          && (ndir != direction))) {
00097        playout = new QBoxLayout(this, QBoxLayout::Down,
00098                              frameWidth(), frameWidth(), name());
00099        playout->setAutoAdd(true);
00100     }
00101 #endif
00102     direction = ndir;
00103 }
00104 
00105 void
00106 IIIMLookupChoiceWidget::update_items(
00107     IIIMCF_lookup_choice ilc
00108 )
00109 {
00110     IIIMF_status st;
00111     IIIMCF_text cand, label;
00112     int i, flag;
00113     int size, idx_first, idx_last, idx_current;
00114     IIIMLookupChoiceItemWidget *piw;
00115 
00116     st = iiimcf_get_lookup_choice_size(ilc, &size,
00117                                    &idx_first, &idx_last, &idx_current);
00118     if (st != IIIMF_STATUS_SUCCESS) return;
00119 
00120     erase_all_items();
00121     for (i = 0; i < size; i++) {
00122        st = iiimcf_get_lookup_choice_item(ilc, i, &cand, &label, &flag);
00123        if ((st == IIIMF_STATUS_SUCCESS)
00124            && (flag & IIIMCF_LOOKUP_CHOICE_ITEM_ENABLED)) {
00125            piw = new IIIMLookupChoiceItemWidget(label, cand, this);
00126            itemlist.push_back(piw);
00127        }
00128     }
00129 }
00130 
00131 void
00132 IIIMLookupChoiceWidget::update_im()
00133 {
00134     IIIMF_status st;
00135     IIIMCF_lookup_choice ilc;
00136 
00137     st = iiimcf_get_lookup_choice(ctx, &ilc);
00138     if (st == IIIMF_STATUS_SUCCESS) {
00139        set_layout(ilc);
00140        update_items(ilc);
00141        show();
00142     } else {
00143        hide();
00144     }
00145 }
00146 
00147 IIIMLookupChoiceWidget::IIIMLookupChoiceWidget(
00148     IIIMCF_context x_ctx,
00149     QWidget *parent,
00150     const char *name,
00151     WFlags f
00152 ) : QHBox(parent, name, f)
00153 {
00154     ctx = x_ctx;
00155     playout = NULL;
00156     setMargin(1);
00157     setFrameStyle(QFrame::GroupBoxPanel | QFrame::Raised);
00158 }
00159 
00160 IIIMLookupChoiceWidget::~IIIMLookupChoiceWidget()
00161 {
00162 }
00163 
00164 /* Local Variables: */
00165 /* c-file-style: "iiim-project" */
00166 /* End: */