Ticket #5149: terminal.patch
File terminal.patch, 6.8 KB (added by , 14 years ago) |
---|
-
AppearPrefView.cpp
13 13 14 14 #include <Button.h> 15 15 #include <ColorControl.h> 16 #include <GridLayoutBuilder.h> 16 17 #include <GroupLayoutBuilder.h> 17 18 #include <LayoutBuilder.h> 18 19 #include <Menu.h> … … 27 28 28 29 29 30 30 AppearancePrefView::AppearancePrefView(const char *name,31 const BMessenger &messenger)31 AppearancePrefView::AppearancePrefView(const char* name, 32 const BMessenger& messenger) 32 33 : BView(name, B_WILL_DRAW), 33 34 fTerminalMessenger(messenger) 34 35 { 35 const char *kColorTable[] = {36 const char* kColorTable[] = { 36 37 PREF_TEXT_FORE_COLOR, 37 38 PREF_TEXT_BACK_COLOR, 38 39 PREF_CURSOR_FORE_COLOR, … … 59 60 60 61 SetLayout(new BGroupLayout(B_HORIZONTAL)); 61 62 62 BMenu *fontMenu = _MakeFontMenu(MSG_HALF_FONT_CHANGED,63 BMenu* fontMenu = _MakeFontMenu(MSG_HALF_FONT_CHANGED, 63 64 PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY), 64 65 PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE)); 65 66 66 BMenu *sizeMenu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED,67 BMenu* sizeMenu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED, 67 68 PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE)); 68 69 69 BView *layoutView = BLayoutBuilder::Group<>() 70 fFont = new BMenuField("Font:", fontMenu); 71 fFontSize = new BMenuField("Size:", sizeMenu); 72 fColorField = new BMenuField("Color:", 73 _MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable, 74 kColorTable[0])); 75 76 BView* layoutView = BLayoutBuilder::Group<>() 70 77 .SetInsets(5, 5, 5, 5) 71 78 .AddGroup(B_VERTICAL, 5) 72 .Add(fFont = new BMenuField("font", "Font:", fontMenu)) 73 .Add(fFontSize = new BMenuField("size", "Size:", sizeMenu)) 74 .Add(fColorField = new BMenuField("color", "Color:", 75 _MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable, 76 kColorTable[0]))) 77 .Add(BSpaceLayoutItem::CreateGlue()) 78 .Add(fColorControl = new BColorControl(BPoint(10, 10), 79 B_CELLS_32x8, 8.0, "", new BMessage(MSG_COLOR_CHANGED))) 79 .Add(BGridLayoutBuilder(5, 5) 80 .Add(fFont->CreateLabelLayoutItem(), 0, 0) 81 .Add(fFont->CreateMenuBarLayoutItem(), 1, 0) 82 .Add(fFontSize->CreateLabelLayoutItem(), 0, 1) 83 .Add(fFontSize->CreateMenuBarLayoutItem(), 1, 1) 84 .Add(fColorField->CreateLabelLayoutItem(), 0, 2) 85 .Add(fColorField->CreateMenuBarLayoutItem(), 1, 2) 86 ) 87 .AddGroup(B_VERTICAL, 5) 88 .AddGlue() 89 .Add(fColorControl = new BColorControl(BPoint(10, 10), 90 B_CELLS_32x8, 8.0, "", new BMessage(MSG_COLOR_CHANGED))) 91 .End() 80 92 .End(); 81 93 82 94 AddChild(layoutView); … … 98 110 99 111 100 112 void 101 AppearancePrefView::GetPreferredSize(float *_width, float *_height)113 AppearancePrefView::GetPreferredSize(float* _width, float* _height) 102 114 { 103 115 if (_width) 104 116 *_width = Bounds().Width(); … … 112 124 AppearancePrefView::Revert() 113 125 { 114 126 fColorField->Menu()->ItemAt(0)->SetMarked(true); 115 fColorControl->SetValue(PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR)); 127 fColorControl->SetValue(PrefHandler::Default()-> 128 getRGB(PREF_TEXT_FORE_COLOR)); 116 129 117 fFont->Menu()->FindItem(PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); 118 fFontSize->Menu()->FindItem(PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); 130 fFont->Menu()-> 131 FindItem(PrefHandler::Default()-> 132 getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); 133 fFontSize->Menu()-> 134 FindItem(PrefHandler::Default()-> 135 getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); 119 136 } 120 137 121 138 … … 131 148 132 149 133 150 void 134 AppearancePrefView::MessageReceived(BMessage *msg)151 AppearancePrefView::MessageReceived(BMessage* msg) 135 152 { 136 153 bool modified = false; 137 154 138 155 switch (msg->what) { 139 156 case MSG_HALF_FONT_CHANGED: 140 157 { 141 const char *family = NULL;142 const char *style = NULL;158 const char* family = NULL; 159 const char* style = NULL; 143 160 msg->FindString("font_family", &family); 144 161 msg->FindString("font_style", &style); 145 162 146 PrefHandler *pref = PrefHandler::Default();147 const char *currentFamily163 PrefHandler* pref = PrefHandler::Default(); 164 const char* currentFamily 148 165 = pref->getString(PREF_HALF_FONT_FAMILY); 149 const char *currentStyle166 const char* currentStyle 150 167 = pref->getString(PREF_HALF_FONT_STYLE); 151 168 if (currentFamily == NULL || strcmp(currentFamily, family) 152 169 || currentStyle == NULL || strcmp(currentStyle, style)) { … … 198 215 199 216 200 217 static bool 201 IsFontUsable(const BFont &font)218 IsFontUsable(const BFont& font) 202 219 { 203 220 // TODO: If BFont::IsFullAndHalfFixed() was implemented, we could 204 221 // use that. But I don't think it's easily implementable using … … 228 245 229 246 230 247 /* static */ 231 BMenu 248 BMenu* 232 249 AppearancePrefView::_MakeFontMenu(uint32 command, 233 const char *defaultFamily, const char *defaultStyle)250 const char* defaultFamily, const char* defaultStyle) 234 251 { 235 BPopUpMenu *menu = new BPopUpMenu("");252 BPopUpMenu* menu = new BPopUpMenu(""); 236 253 int32 numFamilies = count_font_families(); 237 254 uint32 flags; 238 255 … … 246 263 if (get_font_style(family, j, &style) == B_OK) { 247 264 font.SetFamilyAndStyle(family, style); 248 265 if (IsFontUsable(font)) { 249 BMessage *message = new BMessage(command);266 BMessage* message = new BMessage(command); 250 267 message->AddString("font_family", family); 251 268 message->AddString("font_style", style); 252 269 char itemLabel[134]; 253 270 snprintf(itemLabel, sizeof(itemLabel), 254 271 "%s - %s", family, style); 255 BMenuItem *item = new BMenuItem(itemLabel,272 BMenuItem* item = new BMenuItem(itemLabel, 256 273 message); 257 274 menu->AddItem(item); 258 275 if (!strcmp(defaultFamily, family) … … 272 289 273 290 274 291 /* static */ 275 BMenu 292 BMenu* 276 293 AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize) 277 294 { 278 BPopUpMenu *menu = new BPopUpMenu("size");295 BPopUpMenu* menu = new BPopUpMenu("size"); 279 296 int32 sizes[] = {9, 10, 11, 12, 14, 16, 18, 0}; 280 297 281 298 bool found = false; … … 284 301 BString string; 285 302 string << sizes[i]; 286 303 287 BMenuItem *item = new BMenuItem(string.String(), new BMessage(command));304 BMenuItem* item = new BMenuItem(string.String(), new BMessage(command)); 288 305 menu->AddItem(item); 289 306 290 307 if (sizes[i] == defaultSize) { … … 297 314 if (sizes[i] > defaultSize) { 298 315 BString string; 299 316 string << defaultSize; 300 BMenuItem *item = new BMenuItem(string.String(), new BMessage(command));317 BMenuItem* item = new BMenuItem(string.String(), new BMessage(command)); 301 318 item->SetMarked(true); 302 319 menu->AddItem(item, i); 303 320 break; … … 310 327 311 328 312 329 /* static */ 313 BPopUpMenu 314 AppearancePrefView::_MakeMenu(uint32 msg, const char **items,315 const char *defaultItemName)330 BPopUpMenu* 331 AppearancePrefView::_MakeMenu(uint32 msg, const char** items, 332 const char* defaultItemName) 316 333 { 317 BPopUpMenu *menu = new BPopUpMenu("");334 BPopUpMenu* menu = new BPopUpMenu(""); 318 335 319 336 int32 i = 0; 320 337 while (*items) {