SetupWindow.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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): Wade Majors <wade@ezri.org>
  20. * Todd Lair
  21. * Rene Gollent
  22. */
  23. #include <Button.h>
  24. #include <Bitmap.h>
  25. #include <View.h>
  26. #include <MenuField.h>
  27. #include <MenuItem.h>
  28. #include <TranslationUtils.h>
  29. #include "ClickView.h"
  30. #include "ClientWindow.h"
  31. #include "SetupWindow.h"
  32. #include "Vision.h"
  33. #include "NetworkMenu.h"
  34. #include <stdio.h>
  35. SetupWindow::SetupWindow (void)
  36. : BWindow (
  37. BRect (108.0, 88.0, 455.0, 290.0),
  38. S_SETUP_TITLE,
  39. B_TITLED_WINDOW,
  40. B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
  41. {
  42. AddShortcut('/', B_SHIFT_KEY, new BMessage(M_PREFS_SHOW));
  43. bgView = new BView (Bounds(), "background", B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
  44. AddChild (bgView);
  45. bgView->SetViewColor (ui_color (B_PANEL_BACKGROUND_COLOR));
  46. BBitmap *bmp (NULL);
  47. if ((bmp = BTranslationUtils::GetBitmap ('bits', "vision-logo")) != 0)
  48. {
  49. BRect bounds (Bounds());
  50. bounds.left = (bounds.Width() - bmp->Bounds().Width()) / 2.0;
  51. bounds.right = (bounds.left + bmp->Bounds().Width());
  52. bounds.top = 16.0;
  53. bounds.bottom = bounds.top + bmp->Bounds().Height();
  54. ClickView *logo = new ClickView (
  55. bounds,
  56. "image",
  57. B_FOLLOW_LEFT | B_FOLLOW_TOP,
  58. B_WILL_DRAW,
  59. "http://vision.sourceforge.net");
  60. bgView->AddChild (logo);
  61. logo->SetViewBitmap (bmp);
  62. delete bmp;
  63. }
  64. connectButton = new BButton (BRect (0,0,0,0), "connect", S_SETUP_CONNECT_BUTTON,
  65. new BMessage (M_CONNECT_NETWORK));
  66. connectButton->ResizeToPreferred();
  67. netPrefsButton = new BButton (BRect (0,0,0,0), "netprefs", S_SETUP_NETPREFS B_UTF8_ELLIPSIS,
  68. new BMessage (M_NETWORK_SHOW));
  69. netPrefsButton->ResizeToPreferred();
  70. netPrefsButton->SetTarget (vision_app);
  71. prefsButton = new BButton (BRect (0,0,0,0), "prefs", S_SETUP_GENPREFS B_UTF8_ELLIPSIS,
  72. new BMessage (M_PREFS_SHOW));
  73. prefsButton->ResizeToPreferred();
  74. prefsButton->SetTarget (vision_app);
  75. prefsButton->MoveTo (bgView->Bounds().right - (prefsButton->Bounds().Width() + 10),
  76. bgView->Bounds().bottom - (prefsButton->Bounds().Height() + 5));
  77. bgView->AddChild (prefsButton);
  78. netPrefsButton->MoveTo (prefsButton->Frame().left - (netPrefsButton->Bounds().Width() + 5),
  79. prefsButton->Frame().top);
  80. bgView->AddChild (netPrefsButton);
  81. connectButton->MoveTo (netPrefsButton->Frame().left - (connectButton->Bounds().Width() + 15),
  82. prefsButton->Frame().top);
  83. bgView->AddChild (connectButton);
  84. BuildNetworkMenu();
  85. connectButton->SetEnabled (false);
  86. }
  87. SetupWindow::~SetupWindow (void)
  88. {
  89. //
  90. }
  91. bool
  92. SetupWindow::QuitRequested (void)
  93. {
  94. be_app_messenger.SendMessage (M_SETUP_CLOSE);
  95. return true;
  96. }
  97. void
  98. SetupWindow::BuildNetworkMenu (void)
  99. {
  100. BMenu *netMenu (new NetworkMenu (S_SETUP_CHOOSENET, M_SETUP_CHOOSE_NETWORK, BMessenger(this)));
  101. netMenu->SetLabelFromMarked (true);
  102. netList = new BMenuField (BRect (0,0,0,0), "Network List", S_SETUP_CHOOSELABEL, netMenu);
  103. netList->ResizeToPreferred();
  104. netList->SetDivider (be_plain_font->StringWidth (S_SETUP_CHOOSELABEL) + 5);
  105. bgView->AddChild (netList);
  106. netList->MoveTo (10, connectButton->Frame().top - (netList->Bounds().Height() + 20));
  107. }
  108. void
  109. SetupWindow::MessageReceived (BMessage *msg)
  110. {
  111. switch(msg->what)
  112. {
  113. case M_SETUP_CHOOSE_NETWORK:
  114. {
  115. BMenuItem *item (NULL);
  116. msg->FindPointer ("source", reinterpret_cast<void **>(&item));
  117. if (item && vision_app->CheckNetworkValid (item->Label()))
  118. connectButton->SetEnabled (true);
  119. else
  120. connectButton->SetEnabled (false);
  121. }
  122. break;
  123. case M_CONNECT_NETWORK:
  124. {
  125. BMessage connMsg (M_CONNECT_NETWORK);
  126. connMsg.AddString ("network", netList->MenuItem()->Label());
  127. be_app_messenger.SendMessage (&connMsg);
  128. }
  129. break;
  130. case M_PREFS_SHOW:
  131. {
  132. // forwarding Cmd+Shift+/ message
  133. be_app_messenger.SendMessage(msg);
  134. }
  135. break;
  136. default:
  137. BWindow::MessageReceived (msg);
  138. }
  139. }