xref: /aoo42x/main/desktop/source/app/cmdlinehelp.cxx (revision 2722cedd)
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 propotional 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 		"-help/-h/-?   \n"\
68 		"-writer       \n"\
69 		"-calc         \n"\
70 		"-draw         \n"\
71 		"-impress      \n"\
72 		"-base         \n"\
73 		"-math         \n"\
74 		"-global       \n"\
75 		"-web          \n"\
76 		"-o            \n"\
77 		"-n            \n";
78 	const char *aCmdLineHelp_right =
79 		"keep startup bitmap minimized.\n"\
80 		"no startup screen, no default document and no UI.\n"\
81 		"suppress restart/restore after fatal errors.\n"\
82 		"starts the quickstart service (only available on windows and OS/2 platform)\n"\
83 		"don't show startup screen.\n"\
84 		"don't check for remote instances using the installation\n"\
85 		"don't start with an empty document\n"\
86 		"like invisible but no userinteraction at all.\n"\
87 		"show this message and exit.\n"\
88 		"create new text document.\n"\
89 		"create new spreadsheet document.\n"\
90 		"create new drawing.\n"\
91 		"create new presentation.\n"\
92 		"create new database.\n"\
93 		"create new formula.\n"\
94 		"create new global document.\n"\
95 		"create new HTML document.\n"\
96 		"open documents regardless whether they are templates or not.\n"\
97 		"always open documents as new files (use as template).\n";
98 	const char *aCmdLineHelp_bottom =
99 		"-display <display>\n"\
100 		"      Specify X-Display to use in Unix/X11 versions.\n"
101 		"-p <documents...>\n"\
102 		"      print the specified documents on the default printer.\n"\
103 		"-pt <printer> <documents...>\n"\
104 		"      print the specified documents on the specified printer.\n"\
105 		"-view <documents...>\n"\
106 		"      open the specified documents in viewer-(readonly-)mode.\n"\
107 		"-show <presentation>\n"\
108 		"      open the specified presentation and start it immediately\n"\
109 		"-accept=<accept-string>\n"\
110         "      Specify an UNO connect-string to create an UNO acceptor through which\n"\
111 		"      other programs can connect to access the API\n"\
112 		"-unaccept=<accept-string>\n"\
113 		"      Close an acceptor that was created with -accept=<accept-string>\n"\
114 		"      Use -unnaccept=all to close all open acceptors\n"\
115 		"Remaining arguments will be treated as filenames or URLs of documents to open.\n";
116 
117 	void ReplaceStringHookProc( UniString& rStr );
118 
119 	void displayCmdlineHelp()
120 	{
121 		// if you put variables in other chunks don't forget to call the replace routines
122 		// for those chunks...
123 		String aHelpMessage_head(aCmdLineHelp_head, RTL_TEXTENCODING_ASCII_US);
124 		String aHelpMessage_left(aCmdLineHelp_left, RTL_TEXTENCODING_ASCII_US);
125 		String aHelpMessage_right(aCmdLineHelp_right, RTL_TEXTENCODING_ASCII_US);
126 		String aHelpMessage_bottom(aCmdLineHelp_bottom, RTL_TEXTENCODING_ASCII_US);
127 		ReplaceStringHookProc(aHelpMessage_head);
128 		::rtl::OUString aDefault;
129 		String aVerId( ::utl::Bootstrap::getBuildIdData( aDefault ));
130 		aHelpMessage_head.SearchAndReplaceAscii( "%BUILDID", aVerId );
131 		aHelpMessage_head.SearchAndReplaceAscii( "%CMDNAME", String( "soffice", RTL_TEXTENCODING_ASCII_US) );
132 #ifdef UNX
133 		// on unix use console for output
134 		fprintf(stderr, "%s\n", ByteString(aHelpMessage_head,
135 					RTL_TEXTENCODING_ASCII_US).GetBuffer());
136 		// merge left and right column
137 		int n = aHelpMessage_left.GetTokenCount ('\n');
138 		ByteString bsLeft(aHelpMessage_left, RTL_TEXTENCODING_ASCII_US);
139 		ByteString bsRight(aHelpMessage_right, RTL_TEXTENCODING_ASCII_US);
140 		for ( int i = 0; i < n; i++ )
141 		{
142 			fprintf(stderr, "%s", bsLeft.GetToken(i, '\n').GetBuffer());
143 			fprintf(stderr, "%s\n", bsRight.GetToken(i, '\n').GetBuffer());
144 		}
145 		fprintf(stderr, "%s", ByteString(aHelpMessage_bottom,
146                     RTL_TEXTENCODING_ASCII_US).GetBuffer());
147 #else
148 		// rest gets 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
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