00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef INC_MGUI_COMBOBOX_H
00054 #define INC_MGUI_COMBOBOX_H
00055
00056 #ifndef INC_MGUI_CTRL_H
00057 #include <mgui/ctrl.h>
00058 #endif
00059
00060 #ifndef INC_MGUI_LISTITEM_H
00061 #include <mgui/listitem.h>
00062 #endif
00063
00064 namespace MGUI {
00065
00066 #ifndef GENERATING_DOXYGEN_OUTPUT
00067 #ifdef X_NATIVE
00068 class XMLIST;
00069 #endif
00070 #endif // GENERATING_DOXYGEN_OUTPUT
00071
00072
00073
00074
00075 class CTRL_COMBOBOX : public MGUI::CTRL {
00076 public:
00077
00078 enum STYLE {
00079 STYLE_Default = 0x00,
00080 STYLE_Sorted = 0x01
00081 };
00082
00083
00084 CTRL_COMBOBOX (
00085 );
00086
00087
00088 virtual ~CTRL_COMBOBOX (
00089 );
00090
00091
00092
00093
00094
00095 int AddItem (
00096 ID id,
00097 const MISTRING& string,
00098 bool resize = true
00099 );
00100
00101
00102
00103
00104
00105 int AddItem (
00106 ID id,
00107 const char *string,
00108 bool resize = true
00109 );
00110
00111
00112 void AddItems (
00113 const MGUI::LISTITEMDEF *items,
00114 bool resize = true
00115 );
00116
00117
00118
00119 void AddUnitItems (
00120 int UnitType,
00121 int DftUnitID = 0
00122 );
00123
00124
00125 void Create (
00126 MGUI::LAYOUT_PANE_BASE& ParentPane,
00127 const MGUI::LISTITEMDEF *items = 0,
00128 int listheight = 7,
00129 int width = 0,
00130 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00131 STYLE style = STYLE_Default
00132 );
00133
00134
00135 void DeleteAllItems (
00136 );
00137
00138
00139 void DeleteItem (
00140 int index
00141 );
00142
00143
00144 void DeleteItemID (
00145 ID id
00146 );
00147
00148
00149 int GetCount (
00150 ) const;
00151
00152 #ifdef WIN32_MFC
00153
00154 CComboBox& GetCtrl (
00155 ) { return (m_ctrl); }
00156 #endif
00157
00158
00159
00160 int GetIndexFromID (
00161 ID id
00162 ) const;
00163
00164
00165
00166 ID GetItemID (
00167 int index
00168 ) const;
00169
00170
00171
00172 MISTRING GetItemString (
00173 int index
00174 ) const;
00175
00176
00177
00178 int GetSelectedItem (
00179 ) const;
00180
00181
00182
00183 ID GetSelectedItemID (
00184 ) const;
00185
00186
00187
00188 void IniRead (
00189 INIHANDLE IniHandle,
00190 const char *IniGroup,
00191 const char *IniField,
00192 bool notify = true
00193 );
00194
00195
00196 void IniWrite (
00197 INIHANDLE IniHandle,
00198 const char *IniGroup,
00199 const char *IniField
00200 ) const { ::IniWrite(IniHandle,IniGroup,IniField,static_cast<INT32>(GetSelectedItemID())); }
00201
00202
00203
00204
00205 int InsertItem (
00206 int index,
00207 ID id,
00208 const MISTRING& string
00209 );
00210
00211
00212 bool IsItemSelected (
00213 int index
00214 ) const;
00215
00216 #ifdef X_NATIVE
00217
00218 virtual void SetEnabled (
00219 bool enabled = true
00220 );
00221 #endif
00222
00223
00224
00225 void SetSelectedItem (
00226 int index
00227 );
00228
00229
00230
00231
00232 void SetSelectedItemID (
00233 ID id
00234 );
00235
00236
00237 void SetSorted (
00238 bool sorted = true
00239 );
00240
00241
00242 void SizeToContentWidth (
00243 );
00244
00245 protected:
00246
00247
00248
00249 virtual void OnSelection ();
00250
00251 private:
00252 #ifndef GENERATING_DOXYGEN_OUTPUT
00253
00254 #ifdef WIN32_MFC
00255 class MyComboBox : public CComboBox {
00256 public:
00257 MyComboBox (
00258 MGUI::CTRL_COMBOBOX& guictrl
00259 ): m_guictrl(guictrl)
00260 { }
00261 virtual ~MyComboBox (
00262 ) { }
00263 protected:
00264 afx_msg void OnSelendok ();
00265 DECLARE_MESSAGE_MAP()
00266 private:
00267 MGUI::CTRL_COMBOBOX& m_guictrl;
00268 };
00269 friend class MyComboBox;
00270
00271 MyComboBox m_ctrl;
00272 #endif
00273
00274 #ifdef X_NATIVE
00275 Widget m_text;
00276 Widget m_arrowpb;
00277 XMLIST *m_pxmlist;
00278 Widget m_listshell;
00279 int m_listheight;
00280
00281 static void CB_ArrowActivate (Widget, CTRL_COMBOBOX*, void*);
00282 static void CB_ListBrowseSelect (Widget, CTRL_COMBOBOX*, void*);
00283 static void EH_Shell (Widget, CTRL_COMBOBOX*, XEvent*, Boolean*);
00284 void PopdownShell ();
00285 void PopupShell ();
00286 #endif
00287
00288 CTRL_COMBOBOX (const CTRL_COMBOBOX&);
00289 CTRL_COMBOBOX& operator= (const CTRL_COMBOBOX&);
00290 #endif
00291 };
00292
00293 DEFINE_ENUM_OPERATORS(MGUI::CTRL_COMBOBOX::STYLE);
00294
00295
00296
00297
00298 template <class _CT> class CTRL_COMBOBOX_T : public MGUI::CTRL_COMBOBOX {
00299 public:
00300
00301 explicit CTRL_COMBOBOX_T (
00302 ): m_pContainer(0), m_pfOnSelection(0)
00303 { }
00304
00305
00306 void Create (
00307 MGUI::LAYOUT_PANE_BASE& ParentPane,
00308 _CT *pContainer,
00309 void (_CT::*pfOnSelection)(),
00310 const MGUI::LISTITEMDEF *items = 0,
00311 int listheight = 7,
00312 int width = 0,
00313 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00314 STYLE style = STYLE_Default
00315 ) {
00316 m_pContainer = pContainer;
00317 m_pfOnSelection = pfOnSelection;
00318 CTRL_COMBOBOX::Create(ParentPane,items,listheight,width,sizealign,style);
00319 }
00320
00321 private:
00322 #ifndef GENERATING_DOXYGEN_OUTPUT
00323 _CT *m_pContainer;
00324 void (_CT::*m_pfOnSelection)();
00325
00326 virtual void OnSelection (
00327 ) {
00328 CTRL_COMBOBOX::OnSelection();
00329 if (m_pContainer != 0) (m_pContainer->*m_pfOnSelection)();
00330 }
00331 #endif // GENERATING_DOXYGEN_OUTPUT
00332 };
00333
00334
00335
00336
00337 class FORM_COMBOBOX : public MGUI::FORM_COMPOSITE {
00338 public:
00339
00340
00341 FORM_COMBOBOX (
00342 );
00343
00344
00345 virtual ~FORM_COMBOBOX (
00346 );
00347
00348
00349
00350
00351
00352 int AddItem (
00353 ID id,
00354 const MISTRING& string,
00355 bool resize = true
00356 ) { return (m_combobox.AddItem(id,string,resize)); }
00357
00358
00359
00360
00361
00362 int AddItem (
00363 ID id,
00364 const MIUNICODE *string,
00365 bool resize = true
00366 ) { return (m_combobox.AddItem(id,string,resize)); }
00367
00368
00369
00370
00371
00372 int AddItem (
00373 ID id,
00374 const char *string,
00375 bool resize = true
00376 ) { return (m_combobox.AddItem(id,string,resize)); }
00377
00378
00379 void AddItems (
00380 const MGUI::LISTITEMDEF* items,
00381 bool resize = true
00382 ) { m_combobox.AddItems(items,resize); }
00383
00384
00385
00386 void AddUnitItems (
00387 int UnitType,
00388 int DftUnitID = 0
00389 ) { m_combobox.AddUnitItems(UnitType,DftUnitID); }
00390
00391
00392 void Create (
00393 MGUI::LAYOUT_PANE_BASE& ParentPane,
00394 const char* label,
00395 const MGUI::LISTITEMDEF *items = 0,
00396 int listheight = 7,
00397 int width = 0,
00398 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00399 MGUI::CTRL_COMBOBOX::STYLE style = MGUI::CTRL_COMBOBOX::STYLE_Default,
00400 MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00401 );
00402
00403
00404 void Create (
00405 MGUI::LAYOUT_PANE_BASE& ParentPane,
00406 const MISTRING& label,
00407 const MGUI::LISTITEMDEF *items = 0,
00408 int listheight = 7,
00409 int width = 0,
00410 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00411 MGUI::CTRL_COMBOBOX::STYLE style = MGUI::CTRL_COMBOBOX::STYLE_Default,
00412 MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00413 );
00414
00415
00416 void DeleteAllItems (
00417 ) { m_combobox.DeleteAllItems(); }
00418
00419
00420 void DeleteItem (
00421 int index
00422 ) { m_combobox.DeleteItem(index); }
00423
00424
00425 void DeleteItemID (
00426 ID id
00427 ) { m_combobox.DeleteItemID(id); }
00428
00429
00430 CTRL_COMBOBOX& GetComboBox (
00431 ) { return (m_combobox); }
00432
00433
00434 const CTRL_COMBOBOX& GetComboBox (
00435 ) const { return (m_combobox); }
00436
00437
00438 int GetCount (
00439 ) const { return (m_combobox.GetCount()); }
00440
00441
00442
00443 int GetIndexFromID (
00444 ID id
00445 ) const { return (m_combobox.GetIndexFromID(id)); }
00446
00447
00448
00449 ID GetItemID (
00450 int index
00451 ) const { return (m_combobox.GetItemID(index)); }
00452
00453
00454
00455 MISTRING GetItemString (
00456 int index
00457 ) const { return (m_combobox.GetItemString(index)); }
00458
00459
00460
00461 MGUI::CTRL_LABEL& GetLabel (
00462 ) { return (m_label); }
00463
00464
00465
00466 int GetSelectedItem (
00467 ) const { return (m_combobox.GetSelectedItem()); }
00468
00469
00470
00471 ID GetSelectedItemID (
00472 ) const { return (m_combobox.GetSelectedItemID()); }
00473
00474
00475
00476
00477 int InsertItem (
00478 int index,
00479 ID id,
00480 const MISTRING& string
00481 ) { return (m_combobox.InsertItem(index,id,string)); }
00482
00483
00484 bool IsItemSelected (
00485 int index
00486 ) const { return (m_combobox.IsItemSelected(index)); }
00487
00488 #ifdef X_NATIVE
00489
00490 virtual void SetEnabled (
00491 bool enabled = true
00492 );
00493 #endif
00494
00495
00496
00497 void SetSelectedItem (
00498 int index
00499 ) { m_combobox.SetSelectedItem(index); }
00500
00501
00502
00503
00504 void SetSelectedItemID (
00505 ID id
00506 ) { m_combobox.SetSelectedItemID(id); }
00507
00508
00509 void SetSorted (
00510 bool sorted = true
00511 ) { m_combobox.SetSorted(sorted); }
00512
00513 protected:
00514
00515
00516
00517 virtual void OnSelection ();
00518
00519 private:
00520 #ifndef GENERATING_DOXYGEN_OUTPUT
00521
00522 MGUI::CTRL_COMBOBOX_T<FORM_COMBOBOX> m_combobox;
00523 MGUI::CTRL_LABEL m_label;
00524
00525 FORM_COMBOBOX (const FORM_COMBOBOX&);
00526 FORM_COMBOBOX& operator= (const FORM_COMBOBOX&);
00527 #endif // GENERATING_DOXYGEN_OUTPUT
00528 };
00529
00530
00531
00532
00533 template <class _CT> class FORM_COMBOBOX_T : public MGUI::FORM_COMBOBOX {
00534 public:
00535
00536 explicit FORM_COMBOBOX_T (
00537 ): m_pContainer(0), m_pfOnSelection(0)
00538 { }
00539
00540
00541 void Create (
00542 MGUI::LAYOUT_PANE_BASE& ParentPane,
00543 const char* label,
00544 _CT *pContainer,
00545 void (_CT::*pfOnSelection)(),
00546 const MGUI::LISTITEMDEF *items = 0,
00547 int listheight = 7,
00548 int width = 0,
00549 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00550 MGUI::CTRL_COMBOBOX::STYLE style = MGUI::CTRL_COMBOBOX::STYLE_Default,
00551 MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00552 ) {
00553 m_pContainer = pContainer;
00554 m_pfOnSelection = pfOnSelection;
00555 FORM_COMBOBOX::Create(ParentPane,label,items,listheight,width,sizealign,style);
00556 }
00557
00558
00559 void Create (
00560 MGUI::LAYOUT_PANE_BASE& ParentPane,
00561 const MISTRING& label,
00562 _CT *pContainer,
00563 void (_CT::*pfOnSelection)(),
00564 const MGUI::LISTITEMDEF *items = 0,
00565 int listheight = 7,
00566 int width = 0,
00567 MGUI::LAYOUT_SIZEALIGN sizealign = MGUI::LAYOUT_SIZEALIGN_FixedSize,
00568 MGUI::CTRL_COMBOBOX::STYLE style = MGUI::CTRL_COMBOBOX::STYLE_Default,
00569 MGUI::CTRL_LABEL::STYLE labelstyle = MGUI::CTRL_LABEL::STYLE_LeftNoWrap
00570 ) {
00571 m_pContainer = pContainer;
00572 m_pfOnSelection = pfOnSelection;
00573 FORM_COMBOBOX::Create(ParentPane,label,items,listheight,width,sizealign,style);
00574 }
00575
00576 private:
00577 #ifndef GENERATING_DOXYGEN_OUTPUT
00578 _CT *m_pContainer;
00579 void (_CT::*m_pfOnSelection)();
00580
00581 virtual void OnSelection (
00582 ) {
00583 FORM_COMBOBOX::OnSelection();
00584 if (m_pContainer != 0) (m_pContainer->*m_pfOnSelection)();
00585 }
00586 #endif // GENERATING_DOXYGEN_OUTPUT
00587 };
00588
00589
00590
00591 }
00592
00593 #endif // INC_MGUI_COMBOBOX_H