Subject: [beos] 2 new dialogs
From: Stephane Fritsch (sfritsch@noos.fr)
Date: Fri Aug 03 2001 - 04:30:36 CDT
Hello,
Here is a patch for 2 new dialogs on BeOS :
- Dlg_Encoding
- Dlg_Language
I did not use a resource file to store the dialog layout
( this is the method that was used by Chris Plymire who
supply most of the existing dialogs). Instead I wrote the
equivalent code.
This patch also removes a macro (NrElement) which is
now define in XP code. This was causing a compiler
warning.
Stephane
Index: af/xap/beos/xap_BeOSDlg_Encoding.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/xap/beos/xap_BeOSDlg_Encoding.cpp,v
retrieving revision 1.1
diff -u -r1.1 xap_BeOSDlg_Encoding.cpp
--- af/xap/beos/xap_BeOSDlg_Encoding.cpp	2001/07/17 21:48:09	1.1
+++ af/xap/beos/xap_BeOSDlg_Encoding.cpp	2001/08/03 09:05:16
@@ -30,12 +30,124 @@
 #include "xap_Dlg_Encoding.h"
 #include "xap_BeOSDlg_Encoding.h"
 
-#include "ut_Rehydrate.h"
+#include <Window.h>
+#include <View.h>
+#include <ListView.h>
+#include <ScrollView.h>
 
 /*****************************************************************/
 
+class EncodingWin : public BWindow {
+	static const int _eventOK = 'evok';
+	static const int _eventCancel = 'evcl';
+	sem_id modalSem;
+	int32 selection;
+	BListView *listBox;
+public:
+	EncodingWin(BRect &frame, const XAP_StringSet * pSS, UT_uint32 encodCount,
+			const XML_Char ** encodList, UT_uint32 currentEncodIndex);
+	bool SetDlg(UT_uint32 * newEncod);
+	void MessageReceived(BMessage *msg);
+	bool QuitRequested(void);
+};
+
+EncodingWin::EncodingWin(BRect &frame, const XAP_StringSet * pSS, UT_uint32 encodCount,
+			const XML_Char ** encodList, UT_uint32 currentEncodIndex) :
+	BWindow(frame, "EncodingWin", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS)
+{
+	selection = -1;
+	modalSem = create_sem(0,"ParagraphSem");
+
+	SetTitle(pSS->getValue(XAP_STRING_ID_DLG_UENC_EncTitle));
+
+	BView *panel = new BView(Bounds(), "EncodingPanel", B_FOLLOW_ALL_SIDES, B_FRAME_EVENTS | B_WILL_DRAW);
+	panel->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
+	AddChild(panel);
+
+	BRect frame(10,Bounds().bottom-30, 80, 0);
+	panel->AddChild(new BButton(frame, "cancelbutton", pSS->getValue(XAP_STRING_ID_DLG_Cancel),
+				new BMessage(_eventCancel), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM));
+	frame.OffsetBy(frame.Width() + 20, 0);
+	panel->AddChild(new BButton(frame, "okbutton", pSS->getValue(XAP_STRING_ID_DLG_OK),
+				new BMessage(_eventOK), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM));
+
+	frame = Bounds();
+	frame.InsetBy(10,10);
+	frame.right -= B_V_SCROLL_BAR_WIDTH;
+	frame.bottom -= 30.0;	// This space is for the buttons
+	listBox = new BListView(frame,
+			"EncodingList", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
+
+	// Create a scrollView for the list
+	panel->AddChild(new BScrollView("scroll_encodings", listBox,
+		B_FOLLOW_ALL_SIDES, 0, false, true));
+
+	// Add all Elements
+	for (UT_uint32 k=0; k<encodCount; k++) {
+		listBox->AddItem(new BStringItem(encodList[k]));
+	}
+
+	// HighLight the current selection
+	listBox->Select(currentEncodIndex);
+	listBox->ScrollToSelection();
+}
+
+bool EncodingWin::SetDlg(UT_uint32 * newEncod) {
+	status_t        result;
+	Show();
+	thread_id       this_tid = find_thread(NULL);
+	BLooper         *pLoop;
+	BWindow         *pWin = 0;
+
+	pLoop = BLooper::LooperForThread(this_tid);
+	if (pLoop)
+		pWin = dynamic_cast<BWindow*>(pLoop);
+	do {
+		/* HACK : we are in a modal behaviour so events to
+		 * the main window are not delivered. That's why
+		 * we explicitly call UpdateIfNeeded()
+		 */
+		if (pWin) {
+			pWin->Unlock(); // Who will know?=)
+			snooze(100);
+			pWin->Lock();
+
+			// update the window periodically
+			pWin->UpdateIfNeeded();
+		}
+
+		// just wait for exit
+		result = acquire_sem_etc(modalSem, 1, B_TIMEOUT, 1000);
+	} while (result != B_BAD_SEM_ID);
+
+	if (selection >= 0) {
+		*newEncod = selection;
+		return true;
+	} else {
+		return false;
+	}
+}
+
+void EncodingWin::MessageReceived(BMessage *msg) {
+	switch (msg->what) {
+		case _eventOK :
+			selection = listBox->CurrentSelection();
+			// FALL THROUGH
+		case _eventCancel :
+			// Delete the semaphore to end the modal dialogue
+			delete_sem(modalSem);
+			return;
+	}
+	BWindow::MessageReceived(msg);
+}
+
+bool EncodingWin::QuitRequested(void) {
+	delete_sem(modalSem);	// Release the modal behaviour
+	return true;		// Ok to quit this dialog
+}
+
 XAP_Dialog * XAP_BeOSDialog_Encoding::static_constructor(XAP_DialogFactory * pFactory,
-													 XAP_Dialog_Id id)
+								XAP_Dialog_Id id)
 {
         XAP_BeOSDialog_Encoding * p = new XAP_BeOSDialog_Encoding(pFactory,id);
         return p;
@@ -55,8 +167,23 @@
 {
         UT_ASSERT(pFrame);
 
-/*
-	Here, a list of choices + OK + Cancel
-*/	
-	_setAnswer (XAP_Dialog_Encoding::a_CANCEL);
+	XAP_BeOSFrame * pBeOSFrame = static_cast<XAP_BeOSFrame *>(pFrame);
+	BRect parentPosition = pBeOSFrame->getTopLevelWindow()->Frame();
+	// Center the dialog according to the parent
+	BRect dialogPosition = parentPosition;
+	// Let us suppose the dialog is 200x300
+	dialogPosition.InsetBy(-(200-parentPosition.Width())/2, -(300-parentPosition.Height())/2);
+	EncodingWin * dlg = new EncodingWin(dialogPosition, m_pApp->getStringSet(),
+					_getEncodingsCount(), _getAllEncodings(), _getSelectionIndex());
+
+	UT_uint32 newEncod = 0;
+	if (dlg->SetDlg(&newEncod)) {	// Show the window and let the user choose
+		// The user has click "OK"
+		_setEncoding(_getAllEncodings()[newEncod]);
+		_setAnswer(XAP_Dialog_Encoding::a_OK);
+	} else {
+		_setAnswer(XAP_Dialog_Encoding::a_CANCEL);
+	}
+	dlg->Lock();		// Lock it...
+	dlg->Quit();		// to delete it
 }
Index: af/xap/beos/xap_BeOSDlg_Language.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/xap/beos/xap_BeOSDlg_Language.cpp,v
retrieving revision 1.1
diff -u -r1.1 xap_BeOSDlg_Language.cpp
--- af/xap/beos/xap_BeOSDlg_Language.cpp	2001/03/07 15:40:47	1.1
+++ af/xap/beos/xap_BeOSDlg_Language.cpp	2001/08/03 09:05:16
@@ -30,12 +30,132 @@
 #include "xap_Dlg_Language.h"
 #include "xap_BeOSDlg_Language.h"
 
-#include "ut_Rehydrate.h"
+#include <Window.h>
+#include <View.h>
+#include <ListView.h>
+#include <ScrollView.h>
 
 /*****************************************************************/
 
+class LanguageWin : public BWindow {
+	static const int _eventOK = 'evok';
+	static const int _eventCancel = 'evcl';
+	sem_id modalSem;
+	int32 selection;
+	BListView *listBox;
+public:
+	LanguageWin(BRect &frame, const XAP_StringSet * pSS, UT_uint32 langCount,
+			const XML_Char ** langList, const XML_Char *currentLang);
+	bool SetDlg(UT_uint32 * newLang);
+	void MessageReceived(BMessage *msg);
+	bool QuitRequested(void);
+};
+
+LanguageWin::LanguageWin(BRect &frame, const XAP_StringSet * pSS, UT_uint32 langCount, const XML_Char ** langList, const XML_Char *currentLang) :
+	BWindow(frame, "LanguageWin", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS)
+{
+	selection = -1;
+	modalSem = create_sem(0,"ParagraphSem");
+
+	SetTitle(pSS->getValue(XAP_STRING_ID_DLG_ULANG_LangTitle));
+
+	BView *panel = new BView(Bounds(), "LanguagePanel", B_FOLLOW_ALL_SIDES, B_FRAME_EVENTS | B_WILL_DRAW);
+	panel->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
+	AddChild(panel);
+
+	BRect frame(10,Bounds().bottom-30, 80, 0);
+	panel->AddChild(new BButton(frame, "cancelbutton", pSS->getValue(XAP_STRING_ID_DLG_Cancel),
+				new BMessage(_eventCancel), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM));
+	frame.OffsetBy(frame.Width() + 20, 0);
+	panel->AddChild(new BButton(frame, "okbutton", pSS->getValue(XAP_STRING_ID_DLG_OK),
+				new BMessage(_eventOK), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM));
+
+	frame = Bounds();
+	frame.InsetBy(10,10);
+	frame.right -= B_V_SCROLL_BAR_WIDTH;
+	frame.bottom -= 30.0;	// This space is for the buttons
+	listBox = new BListView(frame,
+			"LanguageList", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES);
+
+	// Create a scrollView for the list
+	panel->AddChild(new BScrollView("scroll_languages", listBox,
+		B_FOLLOW_ALL_SIDES, 0, false, true));
+
+	// Add all Elements
+	for (UT_uint32 k=0; k<langCount; k++) {
+		listBox->AddItem(new BStringItem(langList[k]));
+	}
+
+	// HighLight the current selection
+	for (UT_uint32 k=0; k<langCount; k++) {
+		UT_DEBUGMSG(("comparing '%s' and '%s'\n", currentLang, langList[k]));
+		if (currentLang && UT_stricmp(currentLang, langList[k]) == 0) {
+			// This is the current selection
+			UT_DEBUGMSG(("comparison matches \n"));
+			listBox->Select(k);
+			UT_ASSERT(listBox->CurrentSelection()==k);
+			break;
+		}
+	}
+	listBox->ScrollToSelection();
+}
+
+bool LanguageWin::SetDlg(UT_uint32 * newLang) {
+	status_t        result;
+	Show();
+	thread_id       this_tid = find_thread(NULL);
+	BLooper         *pLoop;
+	BWindow         *pWin = 0;
+
+	pLoop = BLooper::LooperForThread(this_tid);
+	if (pLoop)
+		pWin = dynamic_cast<BWindow*>(pLoop);
+	do {
+		/* HACK : we are in a modal behaviour so events to
+		 * the main window are not delivered. That's why
+		 * we explicitly call UpdateIfNeeded()
+		 */
+		if (pWin) {
+			pWin->Unlock(); // Who will know?=)
+			snooze(100);
+			pWin->Lock();
+
+			// update the window periodically
+			pWin->UpdateIfNeeded();
+		}
+
+		// just wait for exit
+		result = acquire_sem_etc(modalSem, 1, B_TIMEOUT, 1000);
+	} while (result != B_BAD_SEM_ID);
+
+	if (selection >= 0) {
+		*newLang = selection;
+		return true;
+	} else {
+		return false;
+	}
+}
+
+void LanguageWin::MessageReceived(BMessage *msg) {
+	switch (msg->what) {
+		case _eventOK :
+			selection = listBox->CurrentSelection();
+			// FALL THROUGH
+		case _eventCancel :
+			// Delete the semaphore to end the modal dialogue
+			delete_sem(modalSem);
+			return;
+	}
+	BWindow::MessageReceived(msg);
+}
+
+bool LanguageWin::QuitRequested(void) {
+	delete_sem(modalSem);	// Release the modal behaviour
+	return true;		// Ok to quit this dialog
+}
+
 XAP_Dialog * XAP_BeOSDialog_Language::static_constructor(XAP_DialogFactory * pFactory,
-													 XAP_Dialog_Id id)
+								XAP_Dialog_Id id)
 {
         XAP_BeOSDialog_Language * p = new XAP_BeOSDialog_Language(pFactory,id);
         return p;
@@ -55,9 +175,27 @@
 {
         UT_ASSERT(pFrame);
 
-/*
-	See xap_Dlg_Language.h for instructions
-*/	
+	XAP_BeOSFrame * pBeOSFrame = static_cast<XAP_BeOSFrame *>(pFrame);
+	BRect parentPosition = pBeOSFrame->getTopLevelWindow()->Frame();
+	// Center the dialog according to the parent
+	BRect dialogPosition = parentPosition;
+	// Let us suppose the dialog is 200x300
+	dialogPosition.InsetBy(-(200-parentPosition.Width())/2, -(300-parentPosition.Height())/2);
+	LanguageWin * dlg = new LanguageWin(dialogPosition, m_pApp->getStringSet(),
+					m_iLangCount, m_ppLanguages, m_pLanguage);
+
+	UT_uint32 newLang = 0;
+	if (dlg->SetDlg(&newLang)) {	// Show the window and let the user choose
+		// The user has click "OK"
+		if (!m_pLanguage || UT_stricmp(m_pLanguage, m_ppLanguages[newLang])) {
+			_setLanguage(m_ppLanguages[newLang]);
+			m_bChangedLanguage = true;
+		}
+		m_answer = XAP_Dialog_Language::a_OK;
+	} else {
+		m_answer = XAP_Dialog_Language::a_CANCEL;
+	}
+	dlg->Lock();		// Lock it...
+	dlg->Quit();		// to delete it
 
-	UT_ASSERT(UT_NOT_IMPLEMENTED);
 }
Index: wp/ap/beos/ap_BeOSApp.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/beos/ap_BeOSApp.cpp,v
retrieving revision 1.45
diff -u -r1.45 ap_BeOSApp.cpp
--- wp/ap/beos/ap_BeOSApp.cpp	2001/07/17 21:48:09	1.45
+++ wp/ap/beos/ap_BeOSApp.cpp	2001/08/03 09:05:26
@@ -226,7 +226,7 @@
 
         m_pClipboard = new AP_BeOSClipboard();
         UT_ASSERT(m_pClipboard);
-	   
+
         m_pEMC = AP_GetEditMethods();
         UT_ASSERT(m_pEMC);
 
@@ -297,7 +297,7 @@
                 if (   (getPrefsValue(AP_PREF_KEY_StringSet,&szStringSet))
                         && (szStringSet)
                         && (*szStringSet)
-			&& (UT_stricmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0))
+			&& (UT_strcmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0))
                 {
                         getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory);
                         UT_ASSERT((szDirectory) && (*szDirectory));
@@ -329,8 +329,6 @@
                 }
         }
         // Now we have the strings loaded we can populate the field names correctly
-	// CHECK THIS: the following was added by a Linux developer who can't test
-	// on BeOS, or even compile, so someone with a BeOS box needs to check it
         int i;
         
         for (i = 0; fp_FieldTypes[i].m_Type != FPFIELDTYPE_END; i++)
@@ -517,7 +515,7 @@
 
 /*****************************************************************/
 
-int AP_BeOSApp::local_main(const char * szAppName, int argc, char ** argv) {
+int AP_BeOSApp::main(const char * szAppName, int argc, char ** argv) {
         // This is a static function.
 #if CONVERT
         bool bShowApp = true;
Index: wp/ap/beos/ap_BeOSApp.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/beos/ap_BeOSApp.h,v
retrieving revision 1.16
diff -u -r1.16 ap_BeOSApp.h
--- wp/ap/beos/ap_BeOSApp.h	2001/07/17 21:48:09	1.16
+++ wp/ap/beos/ap_BeOSApp.h	2001/08/03 09:05:26
@@ -55,7 +55,7 @@
 
         void							ParseCommandLine(void);
         
-	static int local_main (const char * szAppName, int argc, char ** argv);
+	static int main (const char * szAppName, int argc, char ** argv);
 
         void                                             catchSignals(int sig_num);
 
Index: wp/ap/beos/ap_BeOSDialogFactory.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/beos/ap_BeOSDialogFactory.cpp,v
retrieving revision 1.4
diff -u -r1.4 ap_BeOSDialogFactory.cpp
--- wp/ap/beos/ap_BeOSDialogFactory.cpp	1999/11/06 03:23:06	1.4
+++ wp/ap/beos/ap_BeOSDialogFactory.cpp	2001/08/03 09:05:26
@@ -35,8 +35,6 @@
         
 };
 
-#define NrElements(a)	((sizeof(a)/sizeof(a[0])))
-
 /*****************************************************************/
   
 AP_BeOSDialogFactory::AP_BeOSDialogFactory(XAP_App * pApp)
Index: wp/ap/beos/ap_BeOSDialog_All.h
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/beos/ap_BeOSDialog_All.h,v
retrieving revision 1.22
diff -u -r1.22 ap_BeOSDialog_All.h
--- wp/ap/beos/ap_BeOSDialog_All.h	2001/03/07 15:48:46	1.22
+++ wp/ap/beos/ap_BeOSDialog_All.h	2001/08/03 09:05:26
@@ -39,6 +39,7 @@
 #include "xap_BeOSDlg_About.h"
 #include "xap_BeOSDlg_Insert_Symbol.h"
 #include "xap_BeOSDlg_Language.h"
+#include "xap_BeOSDlg_Encoding.h"
 
 
 #include "ap_BeOSDialog_Replace.h"
@@ -66,6 +67,7 @@
         DeclareDialog(XAP_DIALOG_ID_PRINTTOFILE,	XAP_BeOSDialog_FileOpenSaveAs)
         DeclareDialog(XAP_DIALOG_ID_FONT,			XAP_BeOSDialog_FontChooser)
         DeclareDialog(XAP_DIALOG_ID_LANGUAGE,			XAP_BeOSDialog_Language)
+	DeclareDialog(XAP_DIALOG_ID_ENCODING,			XAP_BeOSDialog_Encoding)
         DeclareDialog(XAP_DIALOG_ID_WINDOWMORE,		XAP_BeOSDialog_WindowMore) 
         DeclareDialog(XAP_DIALOG_ID_ZOOM,			XAP_BeOSDialog_Zoom) 
         DeclareDialog(XAP_DIALOG_ID_ABOUT,			XAP_BeOSDialog_About) 
Index: wp/main/beos/BeOSMain.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/main/beos/BeOSMain.cpp,v
retrieving revision 1.2
diff -u -r1.2 BeOSMain.cpp
--- wp/main/beos/BeOSMain.cpp	1999/05/17 16:23:19	1.2
+++ wp/main/beos/BeOSMain.cpp	2001/08/03 09:05:30
@@ -23,5 +23,5 @@
 int main(int argc, char ** argv)
 {
         printf("Starting! \n");
-	return AP_BeOSApp::local_main(ABIWORD_APP_NAME, argc, argv);
+	return AP_BeOSApp::main(ABIWORD_APP_NAME, argc, argv);
 }
This archive was generated by hypermail 2b25 : Fri Aug 03 2001 - 04:30:38 CDT