fat: Greatly simplify and clean up dosfs_get_file_map().
[haiku.git] / src / preferences / dun / NewConnectionWindow.cpp
blobaead640dc43e2d01e10116717f4e5f5214790608
1 /*
3 NewConnectionWindow - DialUp Networking
5 Author: Sikosis (phil@sikosis.com)
7 (C)2002-2004 OpenBeOS under MIT license
9 */
11 // Includes -------------------------------------------------------------------------------------------------- //
12 #include <Alert.h>
13 #include <Application.h>
14 #include <Button.h>
15 #include <Directory.h>
16 #include <Path.h>
17 #include <Screen.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <TextControl.h>
22 #include <Window.h>
23 #include <View.h>
25 #include "DUNWindow.h"
26 #include "NewConnectionWindow.h"
27 #include "DUNView.h"
29 // Constants ------------------------------------------------------------------------------------------------- //
30 const uint32 BTN_ADD = 'BAdd';
31 const uint32 BTN_CANCEL = 'BCnl';
32 const uint32 TXT_NEW_CONNECTION = 'TxCx';
33 // ---------------------------------------------------------------------------------------------------------- //
36 // NewConnectionWindow - Constructor
37 NewConnectionWindow::NewConnectionWindow(BRect frame) : BWindow (frame, "NewConnectionWindow", B_MODAL_WINDOW , B_NOT_RESIZABLE , 0)
39 InitWindow();
40 CenterOnScreen();
41 Show();
45 // NewConnectionWindow - Destructor
46 NewConnectionWindow::~NewConnectionWindow()
48 //exit(0);
52 // NewConnectionWindow::InitWindow
53 void NewConnectionWindow::InitWindow(void)
55 BRect r;
56 r = Bounds(); // the whole view
58 int LeftMargin = 14;
59 int AddButtonSize = 75;
60 int CancelButtonSize = 75;
62 //float CancelLeftMargin = (r.right / 2) - ((AddButtonSize + 20 + CancelButtonSize) / 2);
63 //float AddLeftMargin = CancelLeftMargin + CancelButtonSize + 20;;
65 float AddLeftMargin = r.right - (AddButtonSize + 10);
66 float CancelLeftMargin = AddLeftMargin - (CancelButtonSize + 11);
68 int NewConnectionTop = 10;
70 txtNewConnection = new BTextControl(BRect(LeftMargin,NewConnectionTop,r.right-10,NewConnectionTop+10), "txtNewConnection","Connection name:","New Connection",new BMessage(TXT_NEW_CONNECTION), B_FOLLOW_LEFT | B_FOLLOW_TOP , B_WILL_DRAW | B_NAVIGABLE);
71 txtNewConnection->SetDivider(88);
73 btnCancel = new BButton(BRect (CancelLeftMargin,r.bottom-34,CancelLeftMargin+CancelButtonSize,r.bottom-14),"Cancel","Cancel", new BMessage(BTN_CANCEL), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
74 btnAdd = new BButton(BRect (AddLeftMargin,r.bottom-34,AddLeftMargin+AddButtonSize,r.bottom-14),"Add","Add", new BMessage(BTN_ADD), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
75 btnAdd->MakeDefault(true);
77 AddChild(ptrNewConnectionWindowView = new NewConnectionWindowView(r));
78 ptrNewConnectionWindowView->AddChild(txtNewConnection);
79 ptrNewConnectionWindowView->AddChild(btnCancel);
80 ptrNewConnectionWindowView->AddChild(btnAdd);
81 txtNewConnection->MakeFocus(true);
83 // ---------------------------------------------------------------------------------------------------------- //
85 // NewConnectionWindow::MessageReceived -- receives messages
86 void NewConnectionWindow::MessageReceived (BMessage *message)
88 switch(message->what)
90 case BTN_ADD:
92 // Send Messages to DUNWindow to Add New Connectionupdate
93 BWindow *ptrDUNWindow;
94 ptrDUNWindow = be_app->WindowAt(0); // its the first window
95 BMessage msg(ADD_NEW_CONNECTION);
96 msg.AddString("ConnectionName", txtNewConnection->Text());
97 BMessenger(ptrDUNWindow).SendMessage(&msg);
99 // before closing we need to change the main window to state 1
101 Quit();
103 break;
104 case BTN_CANCEL:
105 Quit();
106 break;
107 default:
108 BWindow::MessageReceived(message);
109 break;
112 // ---------------------------------------------------------------------------------------------------------- //