Dynamicly compute the settings area minimal size (and window, so) according

to add-on's views size.
NetworkSetupProfile class: work in progress...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8758 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2004-09-01 10:10:12 +00:00
parent bb9fc82712
commit 6eb80c55ea
4 changed files with 72 additions and 100 deletions
@@ -73,23 +73,12 @@ status_t NetworkSetupProfile::SetName(const char *name)
} }
void NetworkSetupProfile::Unset()
{
}
bool NetworkSetupProfile::Exists() bool NetworkSetupProfile::Exists()
{ {
return root->Exists(); return root->Exists();
} }
status_t NetworkSetupProfile::Create()
{
return B_ERROR;
}
status_t NetworkSetupProfile::Delete() status_t NetworkSetupProfile::Delete()
{ {
return B_ERROR; return B_ERROR;
@@ -102,13 +91,28 @@ bool NetworkSetupProfile::IsDefault()
} }
bool NetworkSetupProfile::IsActive() bool NetworkSetupProfile::IsCurrent()
{ {
return is_active; return is_current;
} }
status_t NetworkSetupProfile::MakeActive() status_t NetworkSetupProfile::MakeCurrent()
{ {
return B_ERROR; return B_ERROR;
} }
// #pragma mark -
NetworkSetupProfile * NetworkSetupProfile::Default()
{
return NULL;
}
NetworkSetupProfile * NetworkSetupProfile::Current()
{
return NULL;
}
@@ -4,37 +4,41 @@
#include <StorageKit.h> #include <StorageKit.h>
class NetworkSetupProfile { class NetworkSetupProfile {
public: public:
NetworkSetupProfile(); NetworkSetupProfile();
NetworkSetupProfile(const char *path); NetworkSetupProfile(const char *path);
NetworkSetupProfile(const entry_ref *ref); NetworkSetupProfile(const entry_ref *ref);
NetworkSetupProfile(BEntry *entry); NetworkSetupProfile(BEntry *entry);
virtual ~NetworkSetupProfile();
status_t SetTo(const char *path); virtual ~NetworkSetupProfile();
status_t SetTo(const entry_ref *ref);
status_t SetTo(BEntry *entry);
void Unset(); status_t SetTo(const char *path);
status_t SetTo(const entry_ref *ref);
status_t SetTo(BEntry *entry);
bool Exists(); bool Exists();
const char * Name(); const char * Name();
status_t SetName(const char *name); status_t SetName(const char *name);
status_t Create();
status_t Delete();
virtual bool IsDefault(); bool IsDefault();
virtual bool IsActive(); bool IsCurrent();
virtual status_t MakeActive();
private: status_t MakeCurrent();
status_t Delete();
static NetworkSetupProfile * Default();
static NetworkSetupProfile * Current();
private:
BEntry * root; BEntry * root;
BPath * path; BPath * path;
bool is_default; bool is_default;
bool is_active; bool is_current;
const char * name; const char * name;
static BDirectory * profiles_root;
}; };
@@ -19,7 +19,7 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{ {
BMenu *menu; BMenu *menu;
BBox *box, *group, *line; BBox *box, *line; // *group
BButton *button; BButton *button;
BCheckBox *check; BCheckBox *check;
BRect r; BRect r;
@@ -61,41 +61,6 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
box->AddChild(button); box->AddChild(button);
fManageProfilesButton = button; fManageProfilesButton = button;
/*
r.left += w/2 + H_MARGIN;
button = new BButton(r, "new_profile", NEW_PROFILE_LABEL,
new BMessage(NEW_PROFILE_MSG),
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
button->GetPreferredSize(&w, &h);
button->ResizeToPreferred();
box->AddChild(button);
fNewProfileButton = button;
r.left += w + SMALL_MARGIN;
button = new BButton(r, "copy_profile", COPY_PROFILE_LABEL,
new BMessage(COPY_PROFILE_MSG),
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
button->GetPreferredSize(&w, &h);
button->ResizeToPreferred();
box->AddChild(button);
fCopyProfileButton = button;
r.left += w + SMALL_MARGIN;
button = new BButton(r, "delete_profile", DELETE_PROFILE_LABEL,
new BMessage(DELETE_PROFILE_MSG),
B_FOLLOW_TOP | B_FOLLOW_RIGHT);
button->GetPreferredSize(&w, &h);
button->ResizeToPreferred();
box->AddChild(button);
fDeleteProfileButton = button;
r.left = H_MARGIN;
*/
r.top += h + V_MARGIN; r.top += h + V_MARGIN;
// ---- Separator line between Profiles section and Settings section // ---- Separator line between Profiles section and Settings section
@@ -186,8 +151,10 @@ NetworkSetupWindow::NetworkSetupWindow(const char *title)
B_PLAIN_BORDER); B_PLAIN_BORDER);
box->AddChild(fPanel); box->AddChild(fPanel);
fShowRect = fPanel->Bounds(); fAddonView = NULL;
fShowView = NULL;
ResizeTo(fMinAddonViewRect.Width() + 2 * H_MARGIN, fMinAddonViewRect.Height());
SetSizeLimits(Bounds().Width(), 20000, Bounds().Height(), 20000);
} }
@@ -252,32 +219,16 @@ void NetworkSetupWindow::MessageReceived
} }
case SHOW_MSG: { case SHOW_MSG: {
BYAddon *by; if (fAddonView)
NetworkSetupAddOn *addon; fAddonView->RemoveSelf();
if (fShowView) fAddonView = NULL;
fShowView->RemoveSelf(); if (msg->FindPointer("addon_view", (void **) &fAddonView) != B_OK)
fShowView = NULL;
by = NULL;
addon = NULL;
if (msg->FindPointer("addon", (void **) &addon) != B_OK) {
if (msg->FindPointer("byaddon", (void **) &by) != B_OK)
break; break;
};
fShowRect = fPanel->Bounds();
if (addon)
fShowView = addon->CreateView(&fShowRect);
else
fShowView = by->CreateView(&fShowRect);
if (fShowView) {
fPanel->AddChild(fShowView);
// fShowView->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
fShowView->ResizeTo(fPanel->Bounds().Width(), fPanel->Bounds().Height());
};
fPanel->AddChild(fAddonView);
fAddonView->ResizeTo(fPanel->Bounds().Width(), fPanel->Bounds().Height());
fAddonView->SetViewColor((rand() % 256), (rand() % 256), (rand() % 256));
break; break;
} }
@@ -343,7 +294,7 @@ void NetworkSetupWindow::BuildProfilesMenu
item = menu->FindItem(current_profile); item = menu->FindItem(current_profile);
if (item) { if (item) {
BString label; BString label;
bool is_default = (strcmp(current_profile, "default") == 0); // bool is_default = (strcmp(current_profile, "default") == 0);
label << item->Label(); label << item->Label();
label << " (current)"; label << " (current)";
@@ -390,6 +341,8 @@ void NetworkSetupWindow::BuildShowMenu
// Nowhere to search addons!!! // Nowhere to search addons!!!
return; return;
fMinAddonViewRect.Set(0, 0, 200, 200);
search_paths = strdup(search_paths); search_paths = strdup(search_paths);
search_path = strtok_r(search_paths, ":", &next_path_token); search_path = strtok_r(search_paths, ":", &next_path_token);
@@ -443,9 +396,14 @@ void NetworkSetupWindow::BuildShowMenu
while ((addon = get_nth_addon(addon_id, n)) != NULL) { while ((addon = get_nth_addon(addon_id, n)) != NULL) {
BMessage *msg = new BMessage(msg_what); BMessage *msg = new BMessage(msg_what);
BRect r(0, 0, 0, 0);
BView * addon_view = addon->CreateView(&r);
fMinAddonViewRect = fMinAddonViewRect | r;
msg->AddInt32("image_id", addon_id); msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path()); msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("addon", addon); msg->AddPointer("addon", addon);
msg->AddPointer("addon_view", addon_view);
menu->AddItem(new BMenuItem(addon->Name(), msg)); menu->AddItem(new BMenuItem(addon->Name(), msg));
n++; n++;
} }
@@ -458,10 +416,16 @@ void NetworkSetupWindow::BuildShowMenu
BYAddon *addon; BYAddon *addon;
addon = by_instantiate(); addon = by_instantiate();
BRect r(0, 0, 0, 0);
BView * addon_view = addon->CreateView(&r);
fMinAddonViewRect = fMinAddonViewRect | r;
BMessage *msg = new BMessage(msg_what); BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id); msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path()); msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("byaddon", addon); msg->AddPointer("byaddon", addon);
msg->AddPointer("addon_view", addon_view);
menu->AddItem(new BMenuItem(addon->Name(), msg)); menu->AddItem(new BMenuItem(addon->Name(), msg));
continue; continue;
}; };
@@ -64,8 +64,8 @@ class NetworkSetupWindow : public BWindow
BButton *fApplyNowButton; BButton *fApplyNowButton;
BBox *fPanel; BBox *fPanel;
BView *fShowView; BView *fAddonView;
BRect fShowRect; BRect fMinAddonViewRect;
}; };
#endif // ifdef NETWORKSETUPWINDOW_H #endif // ifdef NETWORKSETUPWINDOW_H