PrefEvent.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. */
  21. #include "VTextControl.h"
  22. #include "PrefEvent.h"
  23. #include "Vision.h"
  24. #include <ScrollView.h>
  25. static const char *EventControlLabels[] =
  26. {
  27. S_PREFEVENT_JOIN,
  28. S_PREFEVENT_PART,
  29. S_PREFEVENT_NICK,
  30. S_PREFEVENT_QUIT,
  31. S_PREFEVENT_KICK,
  32. S_PREFEVENT_TOPIC,
  33. S_PREFEVENT_SNOTICE,
  34. S_PREFEVENT_UNOTICE,
  35. S_PREFEVENT_NOTIFYON,
  36. S_PREFEVENT_NOTIFYOFF,
  37. 0
  38. };
  39. EventPrefsView::EventPrefsView (BRect frame)
  40. : BView (frame, "Event prefs", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS)
  41. {
  42. SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  43. BRect bounds (Bounds());
  44. bounds.left += 3;
  45. bounds.right -= B_V_SCROLL_BAR_WIDTH + 3;
  46. bounds.top += 3;
  47. bounds.bottom -= 5;
  48. int32 i (0);
  49. float label_width (0.0);
  50. for (i = 0; EventControlLabels[i]; ++i)
  51. if (StringWidth (EventControlLabels[i]) > label_width)
  52. label_width = StringWidth (EventControlLabels[i]);
  53. BView *bgView (new BView (bounds, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW));
  54. bgView->SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  55. fEvents = new VTextControl * [MAX_EVENTS];
  56. for (i = 0; i < MAX_EVENTS; ++i)
  57. {
  58. fEvents[i] = new VTextControl (
  59. BRect (5, be_plain_font->Size() + ((1.5 * i) * 1.5 * be_plain_font->Size()), 5 + bounds.right - be_plain_font->StringWidth("gP"),
  60. be_plain_font->Size() + (1.5 * (i + 1) * 1.5 * be_plain_font->Size())),
  61. "commands",
  62. EventControlLabels[i],
  63. vision_app->GetEvent (i).String(),
  64. NULL,
  65. B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
  66. fEvents[i]->SetDivider (label_width + 5);
  67. BMessage *msg (new BMessage (M_EVENT_MODIFIED));
  68. msg->AddInt32 ("which", i);
  69. fEvents[i]->SetModificationMessage (msg);
  70. bgView->AddChild (fEvents[i]);
  71. }
  72. fScroller = new BScrollView("command fScroller", bgView, B_FOLLOW_ALL_SIDES,
  73. 0, false, true);
  74. BScrollBar *bar (fScroller->ScrollBar (B_VERTICAL));
  75. fMaxheight = bgView->Bounds().Height();
  76. fProportionheight = fEvents[MAX_EVENTS-1]->Frame().bottom + 10.0;
  77. bar->SetRange (0.0, (fProportionheight - fScroller->Bounds().Height()));
  78. bar->SetProportion (fScroller->Bounds().Height() / fProportionheight);
  79. AddChild (fScroller);
  80. }
  81. EventPrefsView::~EventPrefsView (void)
  82. {
  83. delete [] fEvents;
  84. }
  85. void
  86. EventPrefsView::AttachedToWindow (void)
  87. {
  88. BView::AttachedToWindow ();
  89. for (int32 i = 0; i < MAX_EVENTS; i++)
  90. fEvents[i]->SetTarget (this);
  91. BScrollBar *bar (fScroller->ScrollBar (B_VERTICAL));
  92. if (bar)
  93. bar->SetSteps (3.0, 5.0);
  94. }
  95. void
  96. EventPrefsView::AllAttached (void)
  97. {
  98. BView::AllAttached ();
  99. }
  100. void
  101. EventPrefsView::FrameResized (float width, float height)
  102. {
  103. BView::FrameResized (width, height);
  104. BScrollBar *bar(fScroller->ScrollBar(B_VERTICAL));
  105. if (!bar)
  106. return;
  107. float min, max, scrollheight (fScroller->Bounds().Height());
  108. bar->GetRange (&min, &max);
  109. if (scrollheight < fProportionheight)
  110. {
  111. if (max != fMaxheight)
  112. bar->SetRange (0.0, fProportionheight - scrollheight);
  113. bar->SetProportion (scrollheight / fProportionheight);
  114. }
  115. else
  116. {
  117. bar->SetProportion (1.0);
  118. bar->SetRange (0.0, 0.0);
  119. }
  120. }
  121. void
  122. EventPrefsView::MessageReceived (BMessage *msg)
  123. {
  124. switch (msg->what)
  125. {
  126. case M_EVENT_MODIFIED:
  127. {
  128. int32 which;
  129. msg->FindInt32 ("which", &which);
  130. vision_app->SetEvent (
  131. which,
  132. fEvents[which]->TextView()->Text());
  133. }
  134. break;
  135. default:
  136. BView::MessageReceived (msg);
  137. break;
  138. }
  139. }