OpenClonk
C4FileSelDlg.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2008-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // file selection dialogs
17 
18 #include "C4Include.h"
19 #include "gui/C4FileSelDlg.h"
20 
21 #include "C4Version.h"
22 #include "graphics/C4Draw.h"
23 #include "graphics/C4GraphicsResource.h" // only for single use of ::GraphicsResource.fctOKCancel below...
24 
25 #ifdef _WIN32
26 #ifndef _WIN32_IE
27 #define _WIN32_IE 0x0400
28 #endif
29 #undef MK_ALT
30 #include <shlobj.h>
31 #ifndef CSIDL_MYPICTURES
32 #define CSIDL_MYPICTURES 0x0027
33 #endif
34 #endif
35 
36 // def 1 if gfx loading works in background thread. Right now, it doesn't
37 // C4Group and C4Surface just don't like it
38 // So for now, the loading will be done in 1/10 of the frames in OnIdle of the dialog
39 #define USE_BACKGROUND_THREAD_LOAD 0
40 
41 
42 // ---------------------------------------------------
43 // C4FileSelDlg::ListItem
44 
45 C4FileSelDlg::ListItem::ListItem(const char *szFilename) : C4GUI::Control(C4Rect(0,0,0,0))
46 {
47  if (szFilename) sFilename.Copy(szFilename); else sFilename.Clear();
48 }
49 
51 
52 // ---------------------------------------------------
53 // C4FileSelDlg::DefaultListItem
54 
55 C4FileSelDlg::DefaultListItem::DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon)
56  : C4FileSelDlg::ListItem(szFilename), pLbl(nullptr), pCheck(nullptr), pKeyCheck(nullptr), fGrayed(fGrayed)
57 {
58  StdStrBuf sLabel; if (szFilename) sLabel.Ref(::GetFilename(szFilename)); else sLabel.Ref(LoadResStr("IDS_CTL_NONE"));
59  if (szFilename && fTruncateExtension)
60  {
61  sLabel.Copy();
62  char *szFilename = sLabel.GrabPointer();
63  RemoveExtension(szFilename);
64  sLabel.Take(szFilename);
65  }
67  UpdateSize();
69  int32_t iHeight = caMain.GetInnerHeight();
70  if (fCheckbox)
71  {
72  pCheck = new C4GUI::CheckBox(caMain.GetFromLeft(iHeight), nullptr, false);
73  if (fGrayed) pCheck->SetEnabled(false);
74  AddElement(pCheck);
75  pKeyCheck = new C4KeyBinding(C4KeyCodeEx(K_SPACE), "FileSelToggleFileActive", KEYSCOPE_Gui,
77  }
78  C4GUI::Icon *pIco = new C4GUI::Icon(caMain.GetFromLeft(iHeight), eIcon);
79  AddElement(pIco);
80  pLbl = new C4GUI::Label(sLabel.getData(), caMain.GetAll(), ALeft, fGrayed ? C4GUI_CheckboxDisabledFontClr : C4GUI_CheckboxFontClr);
81  AddElement(pLbl);
82 }
83 
85 {
86  if (pKeyCheck) delete pKeyCheck;
87 }
88 
90 {
92  if (!pLbl) return;
94  caMain.GetFromLeft(caMain.GetInnerHeight()*(1+!!pCheck));
95  pLbl->SetBounds(caMain.GetAll());
96 }
97 
99 {
100  return pCheck ? pCheck->GetChecked() : false;
101 }
102 
104 {
105  // store new state in checkbox
106  if (pCheck) pCheck->SetChecked(fChecked);
107 }
108 
110 {
111  // toggle if possible
112  if (pCheck && !IsGrayed())
113  {
114  pCheck->ToggleCheck(true);
115  return true;
116  }
117  return false;
118 }
119 
120 
121 
122 
123 // ---------------------------------------------------
124 // C4FileSelDlg
125 
126 C4FileSelDlg::C4FileSelDlg(const char *szRootPath, const char *szTitle, C4FileSel_BaseCB *pSelCallback, bool fInitElements)
127  : C4GUI::Dialog(Clamp(C4GUI::GetScreenWdt()*2/3+10, 300,600), Clamp(C4GUI::GetScreenHgt()*2/3+10, 220,500), szTitle, false),
128  pLocationComboBox(nullptr), pFileListBox(nullptr), pSelectionInfoBox(nullptr), btnOK(nullptr), pLocations(nullptr), iLocationCount(0), pSelection(nullptr), pSelCallback(pSelCallback)
129 {
130  sTitle.Copy(szTitle);
131  // key bindings
132  pKeyRefresh = new C4KeyBinding(C4KeyCodeEx(K_F5), "FileSelReload", KEYSCOPE_Gui,
134  pKeyEnterOverride = new C4KeyBinding(C4KeyCodeEx(K_RETURN), "FileSelConfirm", KEYSCOPE_Gui,
136  if (fInitElements) InitElements();
137  sPath.Copy(szRootPath);
138 }
139 
141 {
142  UpdateSize();
143  CStdFont *pUseFont = &(::GraphicsResource.TextFont);
144  // main calcs
145  bool fHasOptions = HasExtraOptions();
146  C4GUI::ComponentAligner caMain(GetClientRect(), 0,0, true);
147  C4Rect rcOptions;
149  if (fHasOptions) rcOptions = caMain.GetFromBottom(pUseFont->GetLineHeight() + 2*C4GUI_DefDlgSmallIndent);
151  // create file selection area
152  if (iLocationCount)
153  {
155  StdStrBuf sText(LoadResStr("IDS_TEXT_LOCATION"));
156  AddElement(new C4GUI::Label(sText.getData(), caLocations.GetFromLeft(pUseFont->GetTextWidth(sText.getData())), ALeft));
157  pLocationComboBox = new C4GUI::ComboBox(caLocations.GetAll());
159  pLocationComboBox->SetText(pLocations[0].sName.getData());
160  }
161  // create file selection area
162  bool fHasPreview = HasPreviewArea();
163  pFileListBox = new C4GUI::ListBox(fHasPreview ? caUpperArea.GetFromLeft(caUpperArea.GetWidth()/2) : caUpperArea.GetAll(), GetFileSelColWidth());
166  if (fHasPreview)
167  {
168  caUpperArea.ExpandLeft(C4GUI_DefDlgIndent);
169  pSelectionInfoBox = new C4GUI::TextWindow(caUpperArea.GetAll());
170  pSelectionInfoBox->SetDecoration(true, true, nullptr, true);
171  }
172  // create button area
173  C4GUI::Button *btnAbort = new C4GUI::CancelButton(caButtonArea.GetFromRight(C4GUI_DefButton2Wdt));
174  btnOK = new C4GUI::OKButton(caButtonArea.GetFromRight(C4GUI_DefButton2Wdt));
175  // add components in tab order
176  if (pLocationComboBox) AddElement(pLocationComboBox);
177  AddElement(pFileListBox);
178  if (pSelectionInfoBox) AddElement(pSelectionInfoBox);
179  if (fHasOptions) AddExtraOptions(rcOptions);
180  AddElement(btnOK);
181  AddElement(btnAbort);
182  SetFocus(pFileListBox, false);
183  // no selection yet
184  UpdateSelection();
185 }
186 
188 {
189  delete [] pLocations;
190  if (pSelCallback) delete pSelCallback;
191  delete pKeyEnterOverride;
192  delete pKeyRefresh;
193 }
194 
196 {
197  // Add all locations
198  for (int32_t i=0; i<iLocationCount; ++i)
199  pFiller->AddEntry(pLocations[i].sName.getData(), i);
200 }
201 
202 bool C4FileSelDlg::OnLocationComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
203 {
204  SetCurrentLocation(idNewSelection, true);
205  // No text change by caller; text alread changed by SetCurrentLocation
206  return true;
207 }
208 
209 void C4FileSelDlg::SetPath(const char *szNewPath, bool fRefresh)
210 {
211  sPath.Copy(szNewPath);
212  if (fRefresh && IsShown()) UpdateFileList();
213 }
214 
216 {
218  // load files
219  UpdateFileList();
220 }
221 
223 {
224  if (!fOK || pSelection)
225  {
226  // allow OK only if something is sth is selected
227  Close(fOK);
228  }
229  else
230  {
231  GetScreen()->ShowErrorMessage(LoadResStr("IDS_ERR_PLEASESELECTAFILEFIRST"));
232  }
233 }
234 
236 {
237  if (fOK && pSelection && pSelCallback)
238  pSelCallback->OnFileSelected(pSelection->GetFilename());
239  // base call: Might delete dlg
241 }
242 
244 {
245  // item double-click: confirms with this file in single mode; toggles selection in multi mode
246  if (IsMultiSelection())
247  {
248  ListItem *pItem = static_cast<ListItem *>(pEl);
249  pItem->UserToggleCheck();
250  }
251  else
252  UserClose(true);
253 }
254 
256 {
257  // Default list item
258  if (szFilename)
259  return new DefaultListItem(szFilename, !!GetFileMask(), IsMultiSelection(), IsItemGrayed(szFilename), GetFileItemIcon());
260  else
261  return new DefaultListItem(nullptr, false, IsMultiSelection(), false, GetFileItemIcon());
262 }
263 
264 void C4FileSelDlg::UpdateFileList()
265 {
267  // reload files
268  C4GUI::Element *pEl;
269  while ((pEl = pFileListBox->GetFirst())) delete pEl;
270  // file items
271  StdStrBuf sSearch;
272  const char *szFileMask = GetFileMask();
273  for (DirectoryIterator iter(sPath.getData()); *iter; ++iter)
274  if (!szFileMask || WildcardListMatch(szFileMask, *iter))
275  pFileListBox->AddElement(CreateListItem(*iter));
276  // none-item?
277  if (HasNoneItem())
278  {
279  pFileListBox->AddElement(CreateListItem(nullptr));
280  }
281  // list now done
283  // path into title
284  const char *szPath = sPath.getData();
285  SetTitle(*szPath ? FormatString("%s [%s]", sTitle.getData(), szPath).getData() : sTitle.getData());
286  // initial no-selection
287  UpdateSelection();
288 }
289 
291 {
292  // update selection from list
293  pSelection = static_cast<ListItem *>(pFileListBox->GetSelectedItem());
294  // OK button only available if selection
295  // SetEnabled would look a lot better here, but it doesn't exist yet :(
296  // selection preview, if enabled
297  if (pSelectionInfoBox)
298  {
299  // default empty
300  pSelectionInfoBox->ClearText(false);
301  if (!pSelection) { pSelectionInfoBox->UpdateHeight(); return; }
302  // add selection description
303  if (pSelection->GetFilename())
304  pSelectionInfoBox->AddTextLine(pSelection->GetFilename(), &::GraphicsResource.TextFont, C4GUI_MessageFontClr, true, false);
305  }
306 }
307 
308 void C4FileSelDlg::SetSelection(const char *szNewSelection, bool fFilenameOnly)
309 {
310  // check all selected definitions
311  for (ListItem *pFileItem = static_cast<ListItem *>(pFileListBox->GetFirst()); pFileItem; pFileItem = static_cast<ListItem *>(pFileItem->GetNext()))
312  {
313  const char *szFileItemFilename = pFileItem->GetFilename();
314  if (fFilenameOnly) szFileItemFilename = GetFilename(szFileItemFilename);
315  pFileItem->SetChecked(SIsModule(szNewSelection, szFileItemFilename));
316  }
317 }
318 
319 StdStrBuf C4FileSelDlg::GetSelection(const char *szFixedSelection, bool fFilenameOnly) const
320 {
321  StdStrBuf sResult;
322  if (!IsMultiSelection())
323  {
324  // get single selected file for single selection dlg
325  if (pSelection) sResult.Copy(fFilenameOnly ? GetFilename(pSelection->GetFilename()) : pSelection->GetFilename());
326  }
327  else
328  {
329  // force fixed selection first
330  if (szFixedSelection) sResult.Append(szFixedSelection);
331  // get ';'-separated list for multi selection dlg
332  for (ListItem *pFileItem = static_cast<ListItem *>(pFileListBox->GetFirst()); pFileItem; pFileItem = static_cast<ListItem *>(pFileItem->GetNext()))
333  if (pFileItem->IsChecked())
334  {
335  const char *szAppendFilename = pFileItem->GetFilename();
336  if (fFilenameOnly) szAppendFilename = GetFilename(szAppendFilename);
337  // prevent adding entries twice (especially those from the fixed selection list)
338  if (!SIsModule(sResult.getData(), szAppendFilename))
339  {
340  if (sResult.getLength()) sResult.AppendChar(';');
341  sResult.Append(szAppendFilename);
342  }
343  }
344  }
345  return sResult;
346 }
347 
348 void C4FileSelDlg::AddLocation(const char *szName, const char *szPath)
349 {
350  // add to list
351  int32_t iNewLocCount = iLocationCount+1;
352  Location *pNewLocations = new Location[iNewLocCount];
353  for (int32_t i=0; i<iLocationCount; ++i) pNewLocations[i] = pLocations[i];
354  pNewLocations[iLocationCount].sName.Copy(szName);
355  pNewLocations[iLocationCount].sPath.Copy(szPath);
356  delete [] pLocations; pLocations = pNewLocations; iLocationCount = iNewLocCount;
357  // first location? Then set path to this
358  if (iLocationCount == 1) SetPath(szPath, false);
359 }
360 
361 void C4FileSelDlg::AddCheckedLocation(const char *szName, const char *szPath)
362 {
363  // check location
364  // path must exit
365  if (!szPath || !*szPath) return;
366  if (!DirectoryExists(szPath)) return;
367  // path must not be in list yet
368  for (int32_t i=0; i<iLocationCount; ++i)
369  if (ItemIdentical(szPath, pLocations[i].sPath.getData()))
370  return;
371  // OK; add it!
372  AddLocation(szName, szPath);
373 }
374 
376 {
377  return iCurrentLocationIndex;
378 }
379 
380 void C4FileSelDlg::SetCurrentLocation(int32_t idx, bool fRefresh)
381 {
382  // safety
383  if (!Inside<int32_t>(idx, 0,iLocationCount)) return;
384  // update ComboBox-text
385  iCurrentLocationIndex = idx;
386  if (pLocationComboBox) pLocationComboBox->SetText(pLocations[idx].sName.getData());
387  // set new path
388  SetPath(pLocations[idx].sPath.getData(), fRefresh);
389 }
390 
391 
392 // ---------------------------------------------------
393 // C4PlayerSelDlg
394 
396  : C4FileSelDlg(Config.General.UserDataPath, LoadResStr("IDS_MSG_SELECTPLR"), pSelCallback)
397 {
398 }
399 
400 
401 // ---------------------------------------------------
402 // C4DefinitionSelDlg
403 
404 C4DefinitionSelDlg::C4DefinitionSelDlg(C4FileSel_BaseCB *pSelCallback, const char *szFixedSelection)
405  : C4FileSelDlg(Config.General.UserDataPath, FormatString(LoadResStr("IDS_MSG_SELECT"), LoadResStr("IDS_DLG_DEFINITIONS")).getData(), pSelCallback)
406 {
407  if (szFixedSelection) sFixedSelection.Copy(szFixedSelection);
408 }
409 
411 {
412  // base call: load file list
414  // initial selection
415  if (sFixedSelection) SetSelection(sFixedSelection.getData(), true);
416 }
417 
418 bool C4DefinitionSelDlg::IsItemGrayed(const char *szFilename) const
419 {
420  // cannot change initial selection
421  if (!sFixedSelection) return false;
422  return SIsModule(sFixedSelection.getData(), GetFilename(szFilename));
423 }
424 
426 {
427  // let the user select definitions by showing a modal selection dialog
428  C4DefinitionSelDlg *pDlg = new C4DefinitionSelDlg(nullptr, pSelection->getData());
429  bool fResult;
430  if ((fResult = pOnScreen->ShowModalDlg(pDlg, false)))
431  {
432  pSelection->Copy(pDlg->GetSelection(pSelection->getData(), true));
433  }
434  delete pDlg;
435  return fResult;
436 }
437 
438 
439 
440 // ---------------------------------------------------
441 // C4PortraitSelDlg::ListItem
442 
443 C4PortraitSelDlg::ListItem::ListItem(const char *szFilename) : C4FileSelDlg::ListItem(szFilename)
444  , fError(false), fLoaded(false)
445 {
446  CStdFont *pUseFont = &(::GraphicsResource.MiniFont);
447  // determine label text
448  StdStrBuf sDisplayLabel;
449  if (szFilename)
450  {
451  sDisplayLabel.Copy(::GetFilename(szFilename));
452  ::RemoveExtension(&sDisplayLabel);
453  }
454  else
455  {
456  sDisplayLabel.Ref(LoadResStr("IDS_MSG_NOPORTRAIT"));
457  }
458  // insert linebreaks into label text
459  int32_t iLineHgt = std::max<int32_t>(pUseFont->BreakMessage(sDisplayLabel.getData(), ImagePreviewSize-6, &sFilenameLabelText, false), 1);
460  // set size
461  SetBounds(C4Rect(0,0,ImagePreviewSize,ImagePreviewSize+iLineHgt));
462 }
463 
464 void C4PortraitSelDlg::ListItem::Load()
465 {
466  if (sFilename)
467  {
468  // safety
469  fLoaded = false;
470  // load image file
471  C4Group SrcGrp;
472  StdStrBuf sParentPath;
473  GetParentPath(sFilename.getData(), &sParentPath);
474  bool fLoadError = true;
475  if (SrcGrp.Open(sParentPath.getData()))
476  if (fctLoadedImage.Load(SrcGrp, ::GetFilename(sFilename.getData()), C4FCT_Full, C4FCT_Full, false, 0))
477  {
478  // image loaded. Can only be put into facet by main thread, because those operations aren't thread safe
479  fLoaded = true;
480  fLoadError = false;
481  }
482  SrcGrp.Close();
483  fError = fLoadError;
484  }
485 }
486 
487 void C4PortraitSelDlg::ListItem::DrawElement(C4TargetFacet &cgo)
488 {
489  // Scale down newly loaded image?
490  if (fLoaded)
491  {
492  fLoaded = false;
493  if (!fctImage.CopyFromSfcMaxSize(fctLoadedImage.GetFace(), ImagePreviewSize))
494  fError = true;
495  fctLoadedImage.GetFace().Clear();
496  fctLoadedImage.Clear();
497  }
498  // Draw picture
499  CStdFont *pUseFont = &(::GraphicsResource.MiniFont);
500  C4Facet cgoPicture(cgo.Surface, cgo.TargetX+rcBounds.x, cgo.TargetY+rcBounds.y, ImagePreviewSize, ImagePreviewSize);
501  if (fError || !sFilename)
502  {
503  C4Facet &fctNoneImg = ::GraphicsResource.fctOKCancel;
504  fctNoneImg.Draw(cgoPicture.Surface, cgoPicture.X+(cgoPicture.Wdt-fctNoneImg.Wdt)/2, cgoPicture.Y+(cgoPicture.Hgt-fctNoneImg.Hgt)/2, 1,0);
505  }
506  else
507  {
508  if (!fctImage.Surface)
509  {
510  // not loaded yet
511  pDraw->TextOut(LoadResStr("IDS_PRC_INITIALIZE"), ::GraphicsResource.MiniFont, 1.0f, cgo.Surface, cgoPicture.X+cgoPicture.Wdt/2, cgoPicture.Y+(cgoPicture.Hgt-::GraphicsResource.MiniFont.GetLineHeight())/2, C4GUI_StatusFontClr, ACenter, false);
512  }
513  else
514  {
515  fctImage.Draw(cgoPicture);
516  }
517  }
518  // draw filename
519  pDraw->TextOut(sFilenameLabelText.getData(), *pUseFont, 1.0f, cgo.Surface, cgoPicture.X+rcBounds.Wdt/2, cgoPicture.Y+cgoPicture.Hgt, C4GUI_MessageFontClr, ACenter, false);
520 }
521 
522 
523 // ---------------------------------------------------
524 // C4PortraitSelDlg::LoaderThread
525 
526 void C4PortraitSelDlg::LoaderThread::ClearLoadItems()
527 {
528  // stop thread so list can be accessed
529  Stop();
530  // clear list
531  LoadItems.clear();
532 }
533 
534 void C4PortraitSelDlg::LoaderThread::AddLoadItem(ListItem *pItem)
535 {
536  // not to be called when thread is running!
537  assert(!IsStarted());
538  LoadItems.push_back(pItem);
539 }
540 
541 void C4PortraitSelDlg::LoaderThread::Execute()
542 {
543  // list empty?
544  if (!LoadItems.size())
545  {
546  // then we're done!
547  SignalStop();
548  return;
549  }
550  // load one item at the time
551  ListItem *pLoadItem = LoadItems.front();
552  pLoadItem->Load();
553  LoadItems.erase(LoadItems.begin());
554 }
555 
556 // ---------------------------------------------------
557 // C4PortraitSelDlg
558 
560  : C4FileSelDlg(Config.General.SystemDataPath, FormatString(LoadResStr("IDS_MSG_SELECT"), LoadResStr("IDS_TYPE_PORTRAIT")).getData(), pSelCallback, false)
561 {
562  char path[_MAX_PATH_LEN];
563  // add common picture locations
564  StdStrBuf strLocation;
566  strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_USERPATH"));
567  AddLocation(strLocation.getData(), path);
569  strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_PROGRAMDIRECTORY"));
570  AddCheckedLocation(strLocation.getData(), path);
571 #ifdef _WIN32
572  wchar_t wpath[MAX_PATH+1];
573  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_PERSONAL, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYDOCUMENTS"), StdStrBuf(wpath).getData());
574  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_MYPICTURES, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYPICTURES"), StdStrBuf(wpath).getData());
575  if (SHGetSpecialFolderPathW(nullptr, wpath, CSIDL_DESKTOPDIRECTORY, false)) AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), StdStrBuf(wpath).getData());
576 #endif
577 #ifdef __APPLE__
578  AddCheckedLocation(LoadResStr("IDS_TEXT_HOME"), getenv("HOME"));
579 #else
580  AddCheckedLocation(LoadResStr("IDS_TEXT_HOMEFOLDER"), getenv("HOME"));
581 #endif
582 #ifndef _WIN32
583  sprintf(path, "%s%c%s", getenv("HOME"), (char)DirectorySeparator, (const char *)"Desktop");
584  AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), path);
585 #endif
586  // build dialog
587  InitElements();
588  // select last location
590 }
591 
593 {
594  // remember location
596  // inherited
598 }
599 
601 {
602  // use own list item type
603  ListItem *pNew = new ListItem(szFilename);;
604  // schedule image loading
605  ImageLoader.AddLoadItem(pNew);
606  return pNew;
607 }
608 
610 {
611  // new file list. Stop loading current
612  ImageLoader.ClearLoadItems();
613 }
614 
616 {
617 #if USE_BACKGROUND_THREAD_LOAD
618  // Begin loading images
619  ImageLoader.Start();
620 #endif
621 }
622 
624 {
625 #if !USE_BACKGROUND_THREAD_LOAD
626  // no multithreading? Workaround for image loading then...
627  static int32_t i = 0;
628  if (!(i++%10)) ImageLoader.Execute();
629 #endif
630 }
631 
633 {
634  // let the user select a portrait by showing a modal selection dialog
635  C4PortraitSelDlg *pDlg = new C4PortraitSelDlg(nullptr);
636  bool fResult;
637  if ((fResult = pOnScreen->ShowModalDlg(pDlg, false)))
638  {
639  pSelection->Take(pDlg->GetSelection(nullptr, false));
640  }
641  delete pDlg;
642  return fResult;
643 }
C4Config Config
Definition: C4Config.cpp:930
C4Draw * pDraw
Definition: C4Draw.cpp:42
const int C4FCT_Full
Definition: C4FacetEx.h:26
C4GameControl Control
C4GraphicsResource GraphicsResource
#define C4GUI_StatusFontClr
Definition: C4Gui.h:42
#define C4GUI_CheckboxFontClr
Definition: C4Gui.h:48
#define C4GUI_ButtonAreaHgt
Definition: C4Gui.h:113
#define C4GUI_CheckboxDisabledFontClr
Definition: C4Gui.h:50
#define C4GUI_DefDlgIndent
Definition: C4Gui.h:132
#define C4GUI_DefButton2Wdt
Definition: C4Gui.h:115
#define C4GUI_DefDlgSmallIndent
Definition: C4Gui.h:133
#define C4GUI_MessageFontClr
Definition: C4Gui.h:43
#define C4GUI_ButtonHgt
Definition: C4Gui.h:111
#define C4GUI_DefButton2HSpace
Definition: C4Gui.h:116
@ KEYSCOPE_Gui
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const int ALeft
Definition: C4Surface.h:41
const int ACenter
Definition: C4Surface.h:41
#define DirectorySeparator
#define _MAX_PATH
#define _MAX_PATH_LEN
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:547
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
#define sprintf
Definition: Standard.h:162
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:708
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:186
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:879
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
bool WildcardListMatch(const char *szWildcardList, const char *szString)
Definition: StdFile.cpp:348
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:303
void TruncateBackslash(char *szFilename)
Definition: StdFile.cpp:263
char SystemDataPath[CFG_MaxString+1]
Definition: C4Config.h:58
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:56
C4ConfigGeneral General
Definition: C4Config.h:255
C4ConfigStartup Startup
Definition: C4Config.h:264
int32_t LastPortraitFolderIdx
Definition: C4Config.h:194
void OnShown() override
bool IsItemGrayed(const char *szFilename) const override
C4DefinitionSelDlg(C4FileSel_BaseCB *pSelCallback, const char *szFixedSelection)
static bool SelectDefinitions(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:561
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
virtual void OnFileSelected(const char *szFilename)=0
void SetChecked(bool fChecked) override
DefaultListItem(const char *szFilename, bool fTruncateExtension, bool fCheckbox, bool fGrayed, C4GUI::Icons eIcon)
bool IsChecked() const override
const char * GetFilename()
Definition: C4FileSelDlg.h:67
virtual bool UserToggleCheck()
Definition: C4FileSelDlg.h:73
ListItem(const char *szFilename)
void AddCheckedLocation(const char *szName, const char *szPath)
void OnLocationComboFill(C4GUI::ComboBox_FillCB *pFiller)
virtual int32_t GetFileSelColWidth() const
Definition: C4FileSelDlg.h:140
void SetCurrentLocation(int32_t idx, bool fRefresh)
bool OnLocationComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
void OnShown() override
void OnSelChange(class C4GUI::Element *pEl)
Definition: C4FileSelDlg.h:142
virtual const char * GetFileMask() const
Definition: C4FileSelDlg.h:131
virtual C4GUI::Icons GetFileItemIcon() const
Definition: C4FileSelDlg.h:139
virtual void BeginFileListUpdate()
Definition: C4FileSelDlg.h:154
virtual bool IsMultiSelection() const
Definition: C4FileSelDlg.h:132
bool KeyRefresh()
Definition: C4FileSelDlg.h:144
virtual bool IsItemGrayed(const char *szFilename) const
Definition: C4FileSelDlg.h:133
virtual bool HasPreviewArea() const
Definition: C4FileSelDlg.h:136
void SetPath(const char *szNewPath, bool fRefresh=true)
virtual void AddExtraOptions(const C4Rect &rcOptionsRect)
Definition: C4FileSelDlg.h:138
StdStrBuf GetSelection(const char *szFixedSelection, bool fFilenameOnly) const
void AddLocation(const char *szName, const char *szPath)
virtual void EndFileListUpdate()
Definition: C4FileSelDlg.h:155
void UserClose(bool fOK) override
virtual ListItem * CreateListItem(const char *szFilename)
int32_t GetCurrentLocationIndex() const
virtual bool HasNoneItem() const
Definition: C4FileSelDlg.h:135
void SetSelection(const char *szNewSelection, bool fFilenameOnly)
void OnClosed(bool fOK) override
C4FileSelDlg(const char *szRootPath, const char *szTitle, C4FileSel_BaseCB *pSelCallback, bool fInitElements=true)
void InitElements()
void OnSelDblClick(class C4GUI::Element *pEl)
virtual void UpdateSelection()
virtual bool HasExtraOptions() const
Definition: C4FileSelDlg.h:137
~C4FileSelDlg() override
void SetEnabled(bool fToVal)
Definition: C4Gui.h:1480
void AddEntry(const char *szText, int32_t id)
static int32_t GetDefaultHeight()
void SetComboCB(ComboBox_FillCB *pNewFillCallback)
void SetText(const char *szToText)
int32_t GetWidth() const
Definition: C4Gui.h:2803
int32_t GetInnerHeight() const
Definition: C4Gui.h:2809
bool GetFromLeft(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
Definition: C4Gui.cpp:1076
void ExpandLeft(int32_t iByWdt)
Definition: C4Gui.h:2812
bool GetFromRight(int32_t iWdt, int32_t iHgt, C4Rect &rcOut)
Definition: C4Gui.cpp:1093
bool GetFromTop(int32_t iHgt, int32_t iWdt, C4Rect &rcOut)
Definition: C4Gui.cpp:1059
void GetAll(C4Rect &rcOut)
Definition: C4Gui.cpp:1125
bool GetFromBottom(int32_t iHgt, int32_t iWdt, C4Rect &rcOut)
Definition: C4Gui.cpp:1109
void AddElement(Element *pChild)
bool KeyEnter()
Definition: C4Gui.h:2134
void SetFocus(Control *pCtrl, bool fByMouse)
void Close(bool fOK)
bool IsShown()
Definition: C4Gui.h:2148
bool fOK
Definition: C4Gui.h:2083
void UpdateSize() override
virtual void OnShown()
Definition: C4Gui.h:2209
Dialog(int32_t iWdt, int32_t iHgt, const char *szTitle, bool fViewportDlg)
virtual void OnClosed(bool fOK)
void SetTitle(const char *szToTitle, bool fShowCloseButton=true)
C4Rect rcBounds
Definition: C4Gui.h:385
virtual Screen * GetScreen()
Definition: C4Gui.cpp:289
C4Rect GetContainedClientRect()
Definition: C4Gui.h:448
virtual void UpdateSize()
Definition: C4Gui.cpp:185
void SetBounds(const C4Rect &rcNewBound)
Definition: C4Gui.h:446
Element * GetSelectedItem()
Definition: C4Gui.h:1581
void SetSelectionDblClickFn(BaseCallbackHandler *pToHandler)
Definition: C4Gui.h:1554
void SetSelectionChangeCallbackFn(BaseCallbackHandler *pToHandler)
Definition: C4Gui.h:1549
bool AddElement(Element *pChild, int32_t iIndent=0)
Element * GetFirst()
Definition: C4Gui.h:1572
bool ShowModalDlg(Dialog *pDlg, bool fDestruct=true)
bool ShowErrorMessage(const char *szMessage)
void SetDecoration(bool fDrawBG, bool fDrawFrame, ScrollBarFacets *pToGfx, bool fAutoScroll)
Definition: C4Gui.h:1753
void ClearText(bool fDoUpdate)
Definition: C4Gui.h:1745
void AddTextLine(const char *szText, CStdFont *pFont, DWORD dwClr, bool fDoUpdate, bool fMakeReadableOnBlack, CStdFont *pCaptionFont=nullptr)
Definition: C4Gui.h:1741
void UpdateHeight()
Definition: C4Gui.h:1751
void UpdateOwnPos() override
C4Rect & GetClientRect() override
Definition: C4Gui.h:864
bool Close()
Definition: C4Group.cpp:971
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660
C4PlayerSelDlg(C4FileSel_BaseCB *pSelCallback)
void OnIdle() override
C4FileSelDlg::ListItem * CreateListItem(const char *szFilename) override
void EndFileListUpdate() override
void OnClosed(bool fOK) override
static bool SelectPortrait(C4GUI::Screen *pOnScreen, StdStrBuf *pSelection)
void BeginFileListUpdate() override
C4PortraitSelDlg(C4FileSel_BaseCB *pSelCallback)
Definition: C4Rect.h:28
int32_t Hgt
Definition: C4Rect.h:30
int Wdt
Definition: C4Surface.h:65
float TargetY
Definition: C4Facet.h:165
float TargetX
Definition: C4Facet.h:165
int GetLineHeight() const
Definition: C4FontLoader.h:125
int32_t GetTextWidth(const char *szText, bool fCheckMarkup=true)
Definition: C4FontLoader.h:140
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)
void Ref(const char *pnData)
Definition: StdBuf.h:455
const char * getData() const
Definition: StdBuf.h:442
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Copy()
Definition: StdBuf.h:467
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
void Clear()
Definition: StdBuf.h:466
size_t getLength() const
Definition: StdBuf.h:445
void Take(char *pnData)
Definition: StdBuf.h:457
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
char * GrabPointer()
Definition: StdBuf.h:459
int32_t GetScreenHgt()
Definition: C4Gui.h:2825
int32_t GetScreenWdt()
Definition: C4Gui.h:2824
Icons
Definition: C4Gui.h:638