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