PrefGeneral.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Rene Gollent
  20. Alan Ellis
  21. */
  22. #include "PrefGeneral.h"
  23. #include "PrefAliases.h"
  24. #include "PrefApp.h"
  25. #include "PrefColor.h"
  26. #include "PrefDCC.h"
  27. #include "PrefFont.h"
  28. #include "PrefCommand.h"
  29. #include "PrefEvent.h"
  30. #include "PrefLog.h"
  31. #include <stdio.h>
  32. #include <Box.h>
  33. #include <ListView.h>
  34. #include <ScrollView.h>
  35. GeneralPrefsView::GeneralPrefsView (BRect frame, const char *title, uint32 redraw, uint32 flags)
  36. : BView (frame, title, redraw, flags),
  37. fLastindex (0)
  38. {
  39. SetViewColor (ui_color(B_PANEL_BACKGROUND_COLOR));
  40. fPrefsItems[piWindow] = new AppWindowPrefsView (BRect(0,0,0,0));
  41. fPrefsItems[piColor] = new ColorPrefsView (BRect (0,0,0,0));
  42. fPrefsBox = new BBox (BRect (0.0, 0.0, fPrefsItems[piColor]->Bounds().right + 10 + be_plain_font->StringWidth("W"), fPrefsItems[piWindow]->Bounds().bottom + be_plain_font->Size() / 2), "Bleat", B_FOLLOW_ALL_SIDES);
  43. fPrefsBox->AddChild(fPrefsItems[piWindow]);
  44. fPrefsBox->AddChild(fPrefsItems[piColor]);
  45. fPrefsList = new BListView (BRect (0.0, 0.0, fPrefsItems[piWindow]->Bounds().right / 2, fPrefsItems[piWindow]->Bounds().bottom), "PrefsList", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
  46. fPrefsList->MoveTo(5, 5);
  47. fPrefsList->AddItem (new BStringItem (S_PREFGEN_ALIAS_ITEM));
  48. fPrefsList->AddItem (new BStringItem (S_PREFGEN_APP_ITEM));
  49. fPrefsList->AddItem (new BStringItem (S_PREFGEN_COLOR_ITEM));
  50. fPrefsList->AddItem (new BStringItem (S_PREFGEN_FONT_ITEM));
  51. fPrefsList->AddItem (new BStringItem (S_PREFGEN_COMMAND_ITEM));
  52. fPrefsList->AddItem (new BStringItem (S_PREFGEN_EVENT_ITEM));
  53. fPrefsList->AddItem (new BStringItem (S_PREFGEN_DCC_ITEM));
  54. fPrefsList->AddItem (new BStringItem (S_PREFGEN_LOG_ITEM));
  55. fPrefsList->SetSelectionMessage (new BMessage (M_GENERALPREFS_SELECTION_CHANGED));
  56. BScrollView *scroller (new BScrollView("list scroller", fPrefsList, B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, 0, false, true));
  57. AddChild(scroller);
  58. ResizeTo(scroller->Frame().right + fPrefsBox->Bounds().Width() + 10, fPrefsBox->Bounds().Height() + 5);
  59. fPrefsBox->MoveTo(scroller->Frame().right + 5, 5);
  60. AddChild (fPrefsBox);
  61. BRect bounds (fPrefsBox->Bounds());
  62. bounds.left += 3;
  63. bounds.right -= 3;
  64. bounds.top += 12;
  65. bounds.bottom -= 5;
  66. fPrefsItems[piAlias] = new AliasesPrefsView (bounds);
  67. fPrefsBox->AddChild (fPrefsItems[piAlias]);
  68. fPrefsItems[piWindow]->MoveTo(be_plain_font->StringWidth("i"), be_plain_font->Size() * 1.5);
  69. fPrefsItems[piWindow]->ResizeBy(be_plain_font->StringWidth("i") * 3, -1.2 * (be_plain_font->Size()));
  70. fPrefsItems[piWindow]->Hide();
  71. fPrefsItems[piColor]->MoveTo(be_plain_font->StringWidth("i"), be_plain_font->Size() * 1.5);
  72. fPrefsItems[piColor]->ResizeTo(bounds.Width() - 3, bounds.Height() - 3);
  73. fPrefsItems[piColor]->Hide();
  74. fPrefsItems[piFonts] = new FontPrefsView (bounds);
  75. fPrefsBox->AddChild (fPrefsItems[piFonts]);
  76. fPrefsItems[piFonts]->Hide();
  77. fPrefsItems[piCommands] = new CommandPrefsView (bounds);
  78. fPrefsBox->AddChild (fPrefsItems[piCommands]);
  79. fPrefsItems[piCommands]->Hide();
  80. fPrefsItems[piEvents] = new EventPrefsView (bounds);
  81. fPrefsBox->AddChild (fPrefsItems[piEvents]);
  82. fPrefsItems[piEvents]->Hide();
  83. fPrefsItems[piDCC] = new DCCPrefsView (bounds);
  84. fPrefsBox->AddChild (fPrefsItems[piDCC]);
  85. fPrefsItems[piDCC]->Hide();
  86. fPrefsItems[piLog] = new LogPrefsView (bounds);
  87. fPrefsBox->AddChild (fPrefsItems[piLog]);
  88. fPrefsItems[piLog]->Hide();
  89. }
  90. GeneralPrefsView::~GeneralPrefsView (void)
  91. {
  92. while (fPrefsList->CountItems() != 0)
  93. delete fPrefsList->RemoveItem ((int32)0);
  94. }
  95. void
  96. GeneralPrefsView::AttachedToWindow (void)
  97. {
  98. BView::AttachedToWindow();
  99. }
  100. void
  101. GeneralPrefsView::AllAttached (void)
  102. {
  103. BView::AllAttached();
  104. fPrefsList->SetTarget(this);
  105. fPrefsList->Select(0);
  106. fPrefsList->MakeFocus();
  107. }
  108. void
  109. GeneralPrefsView::Show (void)
  110. {
  111. BView::Show();
  112. }
  113. void
  114. GeneralPrefsView::MessageReceived (BMessage *msg)
  115. {
  116. switch (msg->what)
  117. {
  118. case M_GENERALPREFS_SELECTION_CHANGED:
  119. {
  120. int32 index (msg->FindInt32 ("index"));
  121. if (index < 0) return;
  122. fPrefsItems[fLastindex]->Hide();
  123. BStringItem *item ((BStringItem *)fPrefsList->ItemAt(index));
  124. fPrefsBox->SetLabel (item->Text());
  125. fPrefsItems[index]->Show();
  126. fLastindex = index;
  127. Invalidate();
  128. }
  129. break;
  130. default:
  131. BView::MessageReceived(msg);
  132. }
  133. }