2003-03-04 12:21:20 +00:00
/*
Devices - DevicesWindow by Sikosis
2004-02-15 20:32:05 +00:00
(C)2003-2004 OBOS
2003-03-04 12:21:20 +00:00
*/
// Includes -------------------------------------------------------------------------------------------------- //
#include <Alert.h>
#include <Application.h>
#include <Bitmap.h>
2003-03-15 01:19:52 +00:00
#include <Box.h>
2003-03-04 12:21:20 +00:00
#include <Button.h>
2003-05-19 13:51:21 +00:00
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <FindDirectory.h>
#include <Node.h>
#include <Path.h>
2003-03-04 12:21:20 +00:00
#include <MenuBar.h>
#include <Menu.h>
#include <MenuItem.h>
2003-03-15 01:19:52 +00:00
#include <OutlineListView.h>
2003-03-04 12:21:20 +00:00
#include <Path.h>
#include <Screen.h>
#include <ScrollView.h>
#include <Shape.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <StringView.h>
#include <Window.h>
#include <View.h>
2003-05-19 13:51:21 +00:00
2003-03-04 12:21:20 +00:00
#include "Devices.h"
#include "DevicesViews.h"
#include "DevicesWindows.h"
const uint32 MENU_FILE_ABOUT_DEVICES = ' mfad ' ;
const uint32 MENU_FILE_QUIT = ' mfqt ' ;
const uint32 MENU_DEVICES_REMOVE_JUMPERED_DEVICE = ' mdrj ' ;
const uint32 MENU_DEVICES_NEW_JUMPERED_DEVICE = ' mdnj ' ;
2003-05-20 10:56:01 +00:00
const uint32 MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM = ' mdcj ' ;
const uint32 MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM = ' mdcm ' ;
2003-03-04 12:21:20 +00:00
const uint32 MENU_DEVICES_RESOURCE_USAGE = ' mdru ' ;
2003-03-15 01:19:52 +00:00
const uint32 BTN_CONFIGURE = ' bcfg ' ;
2003-03-04 12:21:20 +00:00
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
static void CenterWindowOnScreen ( BWindow * w )
{
BRect screenFrame = ( BScreen ( B_MAIN_SCREEN_ID ). Frame ());
BPoint pt ;
pt . x = screenFrame . Width () / 2 - w -> Bounds (). Width () / 2 ;
pt . y = screenFrame . Height () / 2 - w -> Bounds (). Height () / 2 ;
if ( screenFrame . Contains ( pt ))
w -> MoveTo ( pt );
}
// ---------------------------------------------------------------------------------------------------------- //
// DevicesWindow - Constructor
2003-05-19 13:51:21 +00:00
DevicesWindow :: DevicesWindow ( BRect frame ) : BWindow ( frame , "OBOS Devices" , B_TITLED_WINDOW , B_NORMAL_WINDOW_FEEL , 0 )
2003-03-04 12:21:20 +00:00
{
InitWindow ();
CenterWindowOnScreen ( this );
2003-05-19 13:51:21 +00:00
// Load User Settings
BPath path ;
find_directory ( B_USER_SETTINGS_DIRECTORY , & path );
path . Append ( "Devices_Settings" , true );
BFile file ( path . Path (), B_READ_ONLY );
BMessage msg ;
msg . Unflatten ( & file );
LoadSettings ( & msg );
2003-03-04 12:21:20 +00:00
Show ();
}
2003-05-19 13:51:21 +00:00
// ---------------------------------------------------------------------------------------------------------- //
2003-03-04 12:21:20 +00:00
// DevicesWindow - Destructor
DevicesWindow ::~ DevicesWindow ()
{
exit ( 0 );
}
2003-05-19 13:51:21 +00:00
// ---------------------------------------------------------------------------------------------------------- //
2003-03-04 12:21:20 +00:00
// DevicesWindow::InitWindow -- Initialization Commands here
void DevicesWindow :: InitWindow ( void )
{
int LeftMargin = 16 ;
int RightMargin = 246 ;
BRect r ;
r = Bounds (); // the whole view
BMenu * FileMenu ;
BMenu * DevicesMenu ;
2003-05-20 10:56:01 +00:00
BMenu * JumperedDevicesMenu ;
2003-08-16 22:08:30 +00:00
BMenuItem * mniRemoveJumperedDevice ;
2003-03-04 12:21:20 +00:00
// Add the menu bar
menubar = new BMenuBar ( r , "menu_bar" );
// Add File menu to menu bar
FileMenu = new BMenu ( "File" );
2003-07-20 03:47:34 +00:00
FileMenu -> AddItem ( new BMenuItem ( "About Devices" B_UTF8_ELLIPSIS , new BMessage ( MENU_FILE_ABOUT_DEVICES ), 0 ));
2003-03-04 12:21:20 +00:00
FileMenu -> AddSeparatorItem ();
FileMenu -> AddItem ( new BMenuItem ( "Quit" , new BMessage ( MENU_FILE_QUIT ), 'Q' ));
DevicesMenu = new BMenu ( "Devices" );
2003-05-20 10:56:01 +00:00
JumperedDevicesMenu = new BMenu ( "New Jumpered Device" );
2003-07-20 03:47:34 +00:00
JumperedDevicesMenu -> AddItem ( new BMenuItem ( "Custom ..." , new BMessage ( MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM ), 0 ));
JumperedDevicesMenu -> AddItem ( new BMenuItem ( "Modem ..." , new BMessage ( MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM ), 0 ));
2003-05-20 10:56:01 +00:00
//DevicesMenu->AddItem(new BMenuItem("New Jumpered Device", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE), NULL));
DevicesMenu -> AddItem ( JumperedDevicesMenu );
2003-08-16 22:08:30 +00:00
DevicesMenu -> AddItem ( mniRemoveJumperedDevice = new BMenuItem ( "Remove Jumpered Device" , new BMessage ( MENU_DEVICES_REMOVE_JUMPERED_DEVICE ), 'R' ));
2003-03-04 12:21:20 +00:00
DevicesMenu -> AddSeparatorItem ();
DevicesMenu -> AddItem ( new BMenuItem ( "Resource Usage" , new BMessage ( MENU_DEVICES_RESOURCE_USAGE ), 'U' ));
2003-08-16 22:08:30 +00:00
mniRemoveJumperedDevice -> SetEnabled ( false );
2003-03-04 12:21:20 +00:00
menubar -> AddItem ( FileMenu );
menubar -> AddItem ( DevicesMenu );
2003-03-15 01:19:52 +00:00
// Create the StringViews
2003-03-04 12:21:20 +00:00
stvDeviceName = new BStringView ( BRect ( LeftMargin , 16 , 150 , 40 ), "DeviceName" , "Device Name" );
stvCurrentState = new BStringView ( BRect ( RightMargin , 16 , r . right - 10 , 40 ), "CurrentState" , "Current State" );
2003-03-15 01:19:52 +00:00
BStringView * stvIRQ ;
BStringView * stvDMA ;
BStringView * stvIORanges ;
BStringView * stvMemoryRanges ;
float fCurrentHeight = 280 ;
float fCurrentGap = 16 ;
stvIRQ = new BStringView ( BRect ( r . left + 20 , r . top + fCurrentHeight , r . left + 80 , r . top + fCurrentHeight + 20 ), "IRQ" , "IRQs:" );
fCurrentHeight = fCurrentHeight + fCurrentGap ;
stvDMA = new BStringView ( BRect ( r . left + 20 , r . top + fCurrentHeight , r . left + 80 , r . top + fCurrentHeight + 20 ), "DMA" , "DMAs:" );
fCurrentHeight = fCurrentHeight + fCurrentGap ;
stvIORanges = new BStringView ( BRect ( r . left + 20 , r . top + fCurrentHeight , r . left + 80 , r . top + fCurrentHeight + 20 ), "IORanges" , "IO Ranges:" );
fCurrentHeight = fCurrentHeight + fCurrentGap ;
stvMemoryRanges = new BStringView ( BRect ( r . left + 20 , r . top + fCurrentHeight , r . left + 160 , r . top + fCurrentHeight + 20 ), "MemoryRanges" , "Memory Ranges:" );
fCurrentHeight = fCurrentHeight + fCurrentGap ;
// Create the OutlineView
BRect outlinerect ( r . left + 12 , r . top + 50 , r . right - 29 , r . top + 262 );
BOutlineListView * outline ;
BListItem * topmenu ;
BListItem * submenu ;
BScrollView * outlinesv ;
outline = new BOutlineListView ( outlinerect , "devices_list" , B_SINGLE_SELECTION_LIST );
outline -> AddItem ( topmenu = new BStringItem ( "System Devices" ));
outline -> AddUnder ( new BStringItem ( "<no devices>" ), topmenu );
outline -> AddUnder ( new BStringItem ( "<no devices>" ), topmenu );
outline -> AddItem ( topmenu = new BStringItem ( "ISA/Plug and Play Devices" ));
outline -> AddUnder ( submenu = new BStringItem ( "<no devices>" ), topmenu );
outline -> AddItem ( topmenu = new BStringItem ( "PCI Devices" ));
outline -> AddUnder ( submenu = new BStringItem ( "<no devices>" ), topmenu );
outline -> AddItem ( topmenu = new BStringItem ( "Jumpered Devices" ));
outline -> AddUnder ( submenu = new BStringItem ( "<no devices>" ), topmenu );
// Add ScrollView to Devices Window
outlinesv = new BScrollView ( "scroll_devices" , outline , B_FOLLOW_LEFT | B_FOLLOW_TOP , 0 , false , true , B_FANCY_BORDER );
// Setup the OutlineView
outline -> AllAttached ();
outlinesv -> SetBorderHighlighted ( true );
// Back and Fore ground Colours
outline -> SetHighColor ( 0 , 0 , 0 , 0 );
outline -> SetLowColor ( 255 , 255 , 255 , 0 );
// Font Settings
BFont OutlineFont ;
OutlineFont . SetSpacing ( B_CHAR_SPACING );
OutlineFont . SetSize ( 12 );
outline -> SetFont ( & OutlineFont , B_FONT_SHEAR | B_FONT_SPACING );
// Create BBox (or Frame)
BBox * BottomFrame ;
BRect BottomFrameRect ( r . left + 11 , r . bottom - 124 , r . right - 12 , r . bottom - 12 );
BottomFrame = new BBox ( BottomFrameRect , "BottomFrame" , B_FOLLOW_LEFT | B_FOLLOW_TOP , B_WILL_DRAW , B_FANCY_BORDER );
// Create BButton - Configure
BButton * btnConfigure ;
BRect ConfigureButtonRect ( r . left + 298 , r . bottom - 44 , r . right - 23 , r . bottom - 20 );
btnConfigure = new BButton ( ConfigureButtonRect , "btnConfigure" , "Configure" , new BMessage ( BTN_CONFIGURE ), B_FOLLOW_LEFT | B_FOLLOW_TOP , B_WILL_DRAW | B_NAVIGABLE );
btnConfigure -> MakeDefault ( true );
btnConfigure -> SetEnabled ( false );
2003-03-04 12:21:20 +00:00
// Create a basic View
AddChild ( ptrDevicesView = new DevicesView ( r ));
2003-03-15 01:19:52 +00:00
// Add Child(ren)
2003-03-04 12:21:20 +00:00
ptrDevicesView -> AddChild ( menubar );
ptrDevicesView -> AddChild ( stvDeviceName );
ptrDevicesView -> AddChild ( stvCurrentState );
2003-03-15 01:19:52 +00:00
ptrDevicesView -> AddChild ( stvIRQ );
ptrDevicesView -> AddChild ( stvDMA );
ptrDevicesView -> AddChild ( stvIORanges );
ptrDevicesView -> AddChild ( stvMemoryRanges );
ptrDevicesView -> AddChild ( outlinesv );
ptrDevicesView -> AddChild ( btnConfigure );
ptrDevicesView -> AddChild ( BottomFrame );
2003-07-24 14:09:11 +00:00
// Set Window Limits
SetSizeLimits ( 396 , 396 , 400 , 400 );
2003-03-04 12:21:20 +00:00
}
// ---------------------------------------------------------------------------------------------------------- //
// DevicesWindow::FrameResized
void DevicesWindow :: FrameResized ( float width , float height )
{
BRect r ;
r = Bounds ();
// enforce width but not height
}
// ---------------------------------------------------------------------------------------------------------- //
// DevicesWindow::QuitRequested -- Post a message to the app to quit
bool DevicesWindow :: QuitRequested ()
{
2003-05-19 13:51:21 +00:00
SaveSettings ();
be_app -> PostMessage ( B_QUIT_REQUESTED );
return true ;
2003-03-04 12:21:20 +00:00
}
// ---------------------------------------------------------------------------------------------------------- //
2003-05-19 13:51:21 +00:00
// DevicesWindow::LoadSettings -- Loads your current settings
void DevicesWindow :: LoadSettings ( BMessage * msg )
{
BRect frame ;
if ( B_OK == msg -> FindRect ( "windowframe" , & frame )) {
MoveTo ( frame . left , frame . top );
ResizeTo ( frame . right - frame . left , frame . bottom - frame . top );
}
}
// -------------------------------------------------------------------------------------------------------------- //
// DevicesWindow::SaveSettings -- Saves the Users settings
void DevicesWindow :: SaveSettings ( void )
{
BMessage msg ;
msg . AddRect ( "windowframe" , Frame ());
//printf("%i",outline->
BPath path ;
status_t result = find_directory ( B_USER_SETTINGS_DIRECTORY , & path );
if ( result == B_OK )
{
path . Append ( "Devices_Settings" , true );
BFile file ( path . Path (), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE );
msg . Flatten ( & file );
}
}
// ------------------------------------------------------------------------------- //
2003-03-04 12:21:20 +00:00
// DevicesWindow::MessageReceived -- receives messages
void DevicesWindow :: MessageReceived ( BMessage * message )
{
switch ( message -> what )
{
case MENU_FILE_ABOUT_DEVICES :
2003-05-19 13:51:21 +00:00
{
( new BAlert ( "" , "Devices \n\n\t 'Just write a simple app to add a jumpered \n\t device to the system', he said. \n\n\t And many years later another he said \n\t 'recreate it' ;)" , "OK" )) -> Go ();
}
2003-03-04 12:21:20 +00:00
break ;
case MENU_FILE_QUIT :
2003-05-19 13:51:21 +00:00
{
QuitRequested ();
}
2003-03-04 12:21:20 +00:00
break ;
2003-08-23 07:17:03 +00:00
case MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM :
{
ptrModemWindow = new ModemWindow ( BRect ( 0 , 0 , 200 , 194 ));
}
break ;
2003-07-20 04:47:53 +00:00
case MENU_DEVICES_RESOURCE_USAGE :
{
ptrResourceUsageWindow = new ResourceUsageWindow ( BRect ( 0 , 0 , 430 , 350 ));
}
break ;
2003-03-04 12:21:20 +00:00
default :
BWindow :: MessageReceived ( message );
break ;
}
}
// ---------------------------------------------------------------------------------------------------------- //
2003-07-19 11:53:38 +00:00