xref: /haiku/src/tests/kits/interface/bshelf/Container/ContainerWindow.cpp (revision 4a850ca730d8282b5b924e49e09b4ba4d6db7f54)
1 // ContainerWindow.cpp
2 // Generated by Interface Elements (Window v2.3) on Feb 14 2004
3 // This is a user written class and will not be overwritten.
4 
5 #include "ContainerWindow.h"
6 #include <TranslationKit.h>
7 #include <iostream.h>
8 
9 extern const char *PREFS_BACKSTORE_PATH;
10 
11 ContainerWindow :: ContainerWindow(BPositionIO *stream)
12 								 : IEWindow("ContainerWindow")
13 {
14 	Lock();
15 		CreateViewBitmap();
16 
17 		fArchiveStream = stream;
18 		fShelf = new BShelf(fArchiveStream, fContainerView);		// Attach fShelf to fContainerView
19 		fShelf -> SetDisplaysZombies(true);
20 		fArchiveStream -> Seek(0, SEEK_SET);
21 
22 		fRemoveButton = (BButton *)FindView("RemoveButton" );
23 		fTestButton   = (BButton *)FindView("TestButton" );
24 
25 		GetPrefs();
26 	Unlock();
27 	Show();
28 }
29 
30 
31 ContainerWindow :: ~ContainerWindow(void)
32 {
33 	SetPrefs();
34   if (fPrefs != NULL) delete fPrefs;											// now prefs are saved
35 }
36 
37 
38 bool ContainerWindow :: QuitRequested()
39 {
40 //	long c = be_app->CountWindows();
41 //	if (c == 1) be_app->PostMessage(B_QUIT_REQUESTED);
42 	be_app->PostMessage(B_QUIT_REQUESTED);
43 	delete 	fShelf;																	// by deleting the Shelf we'll save the state
44 	fShelf 	= NULL;
45 	return true;
46 }
47 
48 
49 // Handling of user interface and other events
50 void ContainerWindow::MessageReceived(BMessage *message)
51 {
52 	switch(message->what)
53 	{
54 		case IE_CONTAINERWINDOW_MAINMENU_FILE_NEW:    // "New" is selected from menu…
55 			break;
56 
57 		case IE_CONTAINERWINDOW_MAINMENU_FILE_OPEN___:    // "Open…" is selected from menu…
58 			break;
59 
60 		case IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE:    // "Save" is selected from menu…
61 			break;
62 
63 		case IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE_AS___:    // "Save As…" is selected from menu…
64 			break;
65 
66 		case IE_CONTAINERWINDOW_MAINMENU_FILE_ABOUT___:    // "About…" is selected from menu…
67 				PostMessage(B_ABOUT_REQUESTED);
68 			break;
69 
70 		case IE_CONTAINERWINDOW_MAINMENU_FILE_QUIT:    // "Quit" is selected from menu…
71 				PostMessage(B_QUIT_REQUESTED);
72 			break;
73 
74 		case IE_CONTAINERWINDOW_MAINMENU_EDIT_UNDO:    // "Undo" is selected from menu…
75 			break;
76 
77 		case IE_CONTAINERWINDOW_MAINMENU_EDIT_CUT:    // "Cut" is selected from menu…
78 			break;
79 
80 		case IE_CONTAINERWINDOW_MAINMENU_EDIT_COPY:    // "Copy" is selected from menu…
81 			break;
82 
83 		case IE_CONTAINERWINDOW_MAINMENU_EDIT_PASTE:    // "Paste" is selected from menu…
84 			break;
85 
86 		case IE_CONTAINERWINDOW_TESTBUTTON:					// 'TestButton' is pressed...
87 			{
88 				BMessage msg = BMessage(TEST_REPLICANT);
89 				msg.AddBool("Test",true);
90 				be_app ->PostMessage(&msg,be_app);				// Send Info to App
91 
92 				QuitRequested();
93 			}
94 			break;
95 
96 		case IE_CONTAINERWINDOW_REMOVEBUTTON:					// 'RemoveButton' is pressed...
97 			{
98 				BMessage msg = BMessage(CLEAR_FILE);
99 				msg.AddBool("Remove",true);
100 				be_app ->PostMessage(&msg,be_app);				// Send Info to App
101 
102 				QuitRequested();
103 			}
104 			break;
105 
106 
107 		case B_ABOUT_REQUESTED:
108 			{
109 				BAlert	*alert = new BAlert("", "XContainer (H.Reh, dr.hartmut.reh@gmx.de) " "\n" "\n"
110 																		"Based upon Container Demo from Be Inc." "\n"
111 																		"The GUI was created with InterfaceElements (Attila Mezei)" "\n"
112 																		"Please read the ***Be Sample Code License*** "	"\n"
113 																	 ,"OK");
114 				alert -> Go(NULL);
115 			}
116 			break;
117 
118 
119 
120 
121 		default:
122 			BWindow::MessageReceived(message);
123 			break;
124 	}
125 
126 }
127 
128 
129 // Update the menu items before they appear on screen
130 void ContainerWindow::MenusBeginning()
131 {
132 	// Complete the SetEnabled argument or do anything with the source below...
133 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_NEW)				->SetEnabled(false);	// "New"
134 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_OPEN___)		->SetEnabled(false);	// "Open…"
135 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE)				->SetEnabled(false);	// "Save"
136 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_SAVE_AS___)	->SetEnabled(false);	// "Save As…"
137 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_ABOUT___)		->SetEnabled(true);		// "About…"
138 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_FILE_QUIT)				->SetEnabled(true);		// "Quit"
139 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_UNDO)				->SetEnabled(false);	// "Undo"
140 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_CUT)				->SetEnabled(false);	// "Cut"
141 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_COPY)				->SetEnabled(false);	// "Copy"
142 	KeyMenuBar()->FindItem(IE_CONTAINERWINDOW_MAINMENU_EDIT_PASTE)			->SetEnabled(false);	// "Paste"
143 }
144 
145 
146 void ContainerWindow :: CreateViewBitmap()
147 {
148 	// create background bitmap
149 	BBitmap *bitmap = NULL;
150 	fContainerView 	= NULL;
151 	bitmap = BTranslationUtils :: GetBitmap('JPEG',"DropZone.jpeg");		// load bitmap from resource
152 	fContainerView = (BView *)FindView("ContainerView");
153 	if ( (bitmap != NULL) && (fContainerView != NULL) ) fContainerView -> SetViewBitmap(bitmap);
154 	delete bitmap;
155 }
156 
157 
158 void ContainerWindow :: GetPrefs()
159 {
160 	status_t	err;
161 	BRect 		windFrame;
162 
163 
164 	fPrefs = new TPreferences ("XContainer/preferences");			// name of prefs-file
165 	if (fPrefs -> InitCheck() != B_OK)												// if no prefs-> create new
166 	{
167 		windFrame = Frame();																		// get window frame
168 		fPrefs -> SetRect ("WindowFrame", windFrame );
169 	}
170 
171 	err = (fPrefs -> FindRect ("WindowFrame", &windFrame) );
172 	if (err == B_OK)
173 	{
174 		ResizeTo(windFrame.Width(), windFrame.Height() );				// window position and size
175 		MoveTo(windFrame.left, windFrame.top);
176 	}
177 
178 }
179 
180 
181 void ContainerWindow :: SetPrefs()
182 {
183 	fPrefs -> SetRect ("WindowFrame", Frame() );
184 }
185 
186 
187 
188 void ContainerWindow :: EnableRemoveButton(bool enable)
189 {
190 	fRemoveButton -> SetEnabled(enable);
191 }
192 
193 
194 void ContainerWindow :: EnableTestButton(bool enable)
195 {
196 	fTestButton -> SetEnabled(enable);
197 }
198 
199 
200