1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include <stdlib.h>
28 #ifdef UNX
29 #include <stdio.h>
30 #endif
31 #include <sal/types.h>
32 #include <tools/string.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <rtl/bootstrap.hxx>
35 #include <app.hxx>
36 
37 #include "desktopresid.hxx"
38 #include "desktop.hrc"
39 #include "cmdlinehelp.hxx"
40 
41 namespace desktop
42 {
43 	// To be able to display the help nicely in a dialog box with proportional font,
44 	// we need to split it in chunks...
45 	//  ___HEAD___
46 	//  LEFT RIGHT
47 	//  LEFT RIGHT
48 	//  LEFT RIGHT
49 	//  __BOTTOM__
50 	//     [OK]
51 
52 	const char *aCmdLineHelp_head =
53 		"%PRODUCTNAME %PRODUCTVERSION %PRODUCTEXTENSION %BUILDID\n"\
54 		"\n"\
55 		"Usage: %CMDNAME [options] [documents...]\n"\
56 		"\n"\
57 		"Options:\n";
58 	const char *aCmdLineHelp_left =
59 		"-minimized      \n"\
60 		"-invisible      \n"\
61 		"-norestore      \n"\
62 		"-quickstart     \n"\
63 		"-nologo         \n"\
64 		"-nolockcheck    \n"\
65 		"-nodefault      \n"\
66 		"-headless       \n"\
67 		"-conversionmode \n"\
68 		"-help/-h/-?     \n"\
69 		"-writer         \n"\
70 		"-calc           \n"\
71 		"-draw           \n"\
72 		"-impress        \n"\
73 		"-base           \n"\
74 		"-math           \n"\
75 		"-global         \n"\
76 		"-web            \n"\
77 		"-o              \n"\
78 		"-n              \n";
79 	const char *aCmdLineHelp_right =
80 		"Keep startup screen minimized.\n"\
81 		"No startup screen, no default document and no UI.\n"\
82 		"Suppress restart/restore after fatal errors.\n"\
83 		"Start the quickstart service (only available on Windows and OS/2).\n"\
84 		"Don't show startup screen.\n"\
85 		"Don't check for remote instances using the installation.\n"\
86 		"Don't start with an empty document.\n"\
87 		"Like invisible but no user interaction at all.\n"\
88 		"Enable further optimization for document conversion, incl. headless mode.\n"\
89 		"Show this message.\n"\
90 		"Create new text document.\n"\
91 		"Create new spreadsheet document.\n"\
92 		"Create new drawing.\n"\
93 		"Create new presentation.\n"\
94 		"Create new database.\n"\
95 		"Create new formula.\n"\
96 		"Create new global document.\n"\
97 		"Create new HTML document.\n"\
98 		"Open documents regardless whether they are templates or not.\n"\
99 		"Always open documents as new files (use as template).\n";
100 	const char *aCmdLineHelp_bottom =
101 		"-display <display>\n"\
102 		"      Specify X-Display to use in Unix/X11 versions.\n"
103 		"-p <documents...>\n"\
104 		"      Print the specified documents on the default printer.\n"\
105 		"-pt <printer> <documents...>\n"\
106 		"      Print the specified documents on the specified printer.\n"\
107 		"-view <documents...>\n"\
108 		"      Open the specified documents in viewer-(readonly-)mode.\n"\
109 		"-show <presentation>\n"\
110 		"      Open the specified presentation and start it immediately.\n"\
111 		"-accept=<accept-string>\n"\
112 		"      Specify an UNO connect-string to create an UNO acceptor through which\n"\
113 		"      other programs can connect to access the API.\n"\
114 		"-unaccept=<accept-string>\n"\
115 		"      Close an acceptor that was created with -accept=<accept-string>\n"\
116 		"      Use -unnaccept=all to close all open acceptors.\n"\
117 		"Remaining arguments will be treated as filenames or URLs of documents to open.\n";
118 
119 	void ReplaceStringHookProc( UniString& rStr );
120 
displayCmdlineHelp()121 	void displayCmdlineHelp()
122 	{
123 		// If you put variables in other chunks don't forget to call the replace routines
124 		// for those chunks...
125 		String aHelpMessage_head(aCmdLineHelp_head, RTL_TEXTENCODING_ASCII_US);
126 		String aHelpMessage_left(aCmdLineHelp_left, RTL_TEXTENCODING_ASCII_US);
127 		String aHelpMessage_right(aCmdLineHelp_right, RTL_TEXTENCODING_ASCII_US);
128 		String aHelpMessage_bottom(aCmdLineHelp_bottom, RTL_TEXTENCODING_ASCII_US);
129 		ReplaceStringHookProc(aHelpMessage_head);
130 		::rtl::OUString aDefault;
131 		String aVerId( ::utl::Bootstrap::getBuildIdData( aDefault ));
132 		aHelpMessage_head.SearchAndReplaceAscii( "%BUILDID", aVerId );
133 		aHelpMessage_head.SearchAndReplaceAscii( "%CMDNAME", String( "soffice", RTL_TEXTENCODING_ASCII_US) );
134 #ifdef UNX
135 		// On Unix use console for output
136 		fprintf(stderr, "%s\n", ByteString(aHelpMessage_head, RTL_TEXTENCODING_ASCII_US).GetBuffer());
137 		// Merge left and right column
138 		int n = aHelpMessage_left.GetTokenCount ('\n');
139 		ByteString bsLeft(aHelpMessage_left, RTL_TEXTENCODING_ASCII_US);
140 		ByteString bsRight(aHelpMessage_right, RTL_TEXTENCODING_ASCII_US);
141 		for ( int i = 0; i < n; i++ )
142 		{
143 			fprintf(stderr, "%s", bsLeft.GetToken(i, '\n').GetBuffer());
144 			fprintf(stderr, "%s\n", bsRight.GetToken(i, '\n').GetBuffer());
145 		}
146 		fprintf(stderr, "%s", ByteString(aHelpMessage_bottom, RTL_TEXTENCODING_ASCII_US).GetBuffer());
147 #else
148 		// All other get a dialog box
149 		CmdlineHelpDialog aDlg;
150 		aDlg.m_ftHead.SetText(aHelpMessage_head);
151 		aDlg.m_ftLeft.SetText(aHelpMessage_left);
152 		aDlg.m_ftRight.SetText(aHelpMessage_right);
153 		aDlg.m_ftBottom.SetText(aHelpMessage_bottom);
154 		aDlg.Execute();
155 #endif
156 	}
157 #ifndef UNX
CmdlineHelpDialog(void)158 	CmdlineHelpDialog::CmdlineHelpDialog (void)
159 	: ModalDialog( NULL, DesktopResId( DLG_CMDLINEHELP ) )
160 	, m_ftHead( this, DesktopResId( TXT_DLG_CMDLINEHELP_HEADER ) )
161 	, m_ftLeft( this, DesktopResId( TXT_DLG_CMDLINEHELP_LEFT ) )
162 	, m_ftRight( this, DesktopResId( TXT_DLG_CMDLINEHELP_RIGHT ) )
163 	, m_ftBottom( this, DesktopResId( TXT_DLG_CMDLINEHELP_BOTTOM ) )
164 	, m_btOk( this, DesktopResId( BTN_DLG_CMDLINEHELP_OK ) )
165 	{
166 		FreeResource();
167 	}
168 #endif
169 }
170