xref: /aoo42x/main/desktop/source/app/cmdlinehelp.cxx (revision 52812967)
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 bitmap minimized.\n"\
81 		"no startup screen, no default document and no UI.\n"\
82 		"suppress restart/restore after fatal errors.\n"\
83 		"starts 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, includes headless mode.\n"\
89 		"show this message and exit.\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 
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,
137 					RTL_TEXTENCODING_ASCII_US).GetBuffer());
138 		// merge left and right column
139 		int n = aHelpMessage_left.GetTokenCount ('\n');
140 		ByteString bsLeft(aHelpMessage_left, RTL_TEXTENCODING_ASCII_US);
141 		ByteString bsRight(aHelpMessage_right, RTL_TEXTENCODING_ASCII_US);
142 		for ( int i = 0; i < n; i++ )
143 		{
144 			fprintf(stderr, "%s", bsLeft.GetToken(i, '\n').GetBuffer());
145 			fprintf(stderr, "%s\n", bsRight.GetToken(i, '\n').GetBuffer());
146 		}
147 		fprintf(stderr, "%s", ByteString(aHelpMessage_bottom,
148 					RTL_TEXTENCODING_ASCII_US).GetBuffer());
149 #else
150 		// rest gets a dialog box
151 		CmdlineHelpDialog aDlg;
152 		aDlg.m_ftHead.SetText(aHelpMessage_head);
153 		aDlg.m_ftLeft.SetText(aHelpMessage_left);
154 		aDlg.m_ftRight.SetText(aHelpMessage_right);
155 		aDlg.m_ftBottom.SetText(aHelpMessage_bottom);
156 		aDlg.Execute();
157 #endif
158 	}
159 #ifndef UNX
160 	CmdlineHelpDialog::CmdlineHelpDialog (void)
161 	: ModalDialog( NULL, DesktopResId( DLG_CMDLINEHELP ) )
162 	, m_ftHead( this, DesktopResId( TXT_DLG_CMDLINEHELP_HEADER ) )
163 	, m_ftLeft( this, DesktopResId( TXT_DLG_CMDLINEHELP_LEFT ) )
164 	, m_ftRight( this, DesktopResId( TXT_DLG_CMDLINEHELP_RIGHT ) )
165 	, m_ftBottom( this, DesktopResId( TXT_DLG_CMDLINEHELP_BOTTOM ) )
166 	, m_btOk( this, DesktopResId( BTN_DLG_CMDLINEHELP_OK ) )
167 	{
168 		FreeResource();
169 	}
170 #endif
171 }
172