SizeComboBox.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* ==========================================================================
  2. File : SizeComboBox.cpp
  3. Class : CSizeComboBox
  4. Author : Johan Rosengren, Abstrakt Mekanik AB
  5. Iain Clarke
  6. Date : 2005-05-06
  7. Purpose : "CSizeComboBox" is derived from "CComboBox" and is a simple
  8. combobox for displaying a selection of font sizes.
  9. Description : Simpel derived class with members to fill the box and
  10. select an entry by contents instead of index.
  11. Usage : Create as any combobox, and call "FillCombo" to fill
  12. the control with a selection of font sizes. Call
  13. "SelectFontSize" to select an entry by content.
  14. ========================================================================*/
  15. #include "stdafx.h"
  16. #include "SizeComboBox.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSizeComboBox
  24. CSizeComboBox::CSizeComboBox()
  25. /* ============================================================
  26. Function : CSizeComboBox::CSizeComboBox
  27. Description : ctor
  28. Access : Public
  29. Return : void
  30. Parameters : none
  31. Usage :
  32. ============================================================*/
  33. {
  34. }
  35. CSizeComboBox::~CSizeComboBox()
  36. /* ============================================================
  37. Function : CSizeComboBox::~CSizeComboBox
  38. Description : dtor
  39. Access : Public
  40. Return : void
  41. Parameters : none
  42. Usage :
  43. ============================================================*/
  44. {
  45. }
  46. BEGIN_MESSAGE_MAP(CSizeComboBox, CComboBox)
  47. //{{AFX_MSG_MAP(CSizeComboBox)
  48. // NOTE - the ClassWizard will add and remove mapping macros here.
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CSizeComboBox message handlers
  53. void CSizeComboBox::SelectSize( int size )
  54. /* ============================================================
  55. Function : CSizeComboBox::SelectSize
  56. Description : Selects the entry corresponding to "size",
  57. if it exists in the list.
  58. Access : Public
  59. Return : void
  60. Parameters : int size - Size to select
  61. Usage : Call to select an entry by value in the
  62. combo list.
  63. ============================================================*/
  64. {
  65. CString sz;
  66. sz.Format( _T( "%d" ), size );
  67. int max = GetCount();
  68. for( int t = 0 ; t < max ; t++ )
  69. {
  70. CString data;
  71. GetLBText( t, data );
  72. if( data == sz )
  73. {
  74. SetCurSel( t );
  75. return;
  76. }
  77. }
  78. }
  79. void CSizeComboBox::FillCombo()
  80. /* ============================================================
  81. Function : CSizeComboBox::FillCombo
  82. Description : Fills the combo box with a fairly standard
  83. selection of font sizes.
  84. Access : Public
  85. Return : void
  86. Parameters : none
  87. Usage : Call to fill the combobox.
  88. ============================================================*/
  89. {
  90. AddString( _T( "8" ) );
  91. AddString( _T( "9" ) );
  92. AddString( _T( "10" ) );
  93. AddString( _T( "11" ) );
  94. AddString( _T( "12" ) );
  95. AddString( _T( "14" ) );
  96. AddString( _T( "16" ) );
  97. AddString( _T( "18" ) );
  98. AddString( _T( "20" ) );
  99. AddString( _T( "22" ) );
  100. AddString( _T( "24" ) );
  101. AddString( _T( "26" ) );
  102. AddString( _T( "28" ) );
  103. AddString( _T( "36" ) );
  104. AddString( _T( "48" ) );
  105. AddString( _T( "72" ) );
  106. }