/** * This function returns a WndForm created either from the ressources or * from the XML file in XCSoarData(if found) * @param LookUpTable The CallBackTable * @param FileName The XML filename to search for in XCSoarData * @param Parent The parent window (e.g. XCSoarInterface::main_window) * @param resource The resource to look for * @return The WndForm object */ WndForm * LoadDialog(CallBackTableEntry *LookUpTable, SingleWindow &Parent, const TCHAR* resource) { WndForm *form = NULL; // Find XML file or resource and load XML data out of it XMLNode node = xmlOpenResourceHelper(resource); // TODO code: put in error checking here and get rid of exits in xmlParser // If XML error occurred -> Error messagebox + cancel if (node.isEmpty()) { ShowXMLError(); return NULL; } // If the main XMLNode is of type "Form" if (_tcsicmp(node.getName(), _T("Form")) != 0) // Get the first child node of the type "Form" // and save it as the dialog node node = node.getChildNode(_T("Form")); // If Node does not exists -> Error messagebox + cancel if (node.isEmpty()) { ShowXMLError(); return NULL; } // Determine the dialog style of the dialog DialogStyle dialog_style = GetDialogStyle(node); // Determine the dialog size const TCHAR* Caption = GetCaption(node); const RECT rc = Parent.get_client_rect(); ControlPosition pos = GetPosition(node, rc); ControlSize size = GetSize(node, rc, pos); InitScaleWidth(size, rc, dialog_style); // Correct dialog size and position for dialog style switch (dialog_style) { case dsFullWidth: pos.x = rc.left; pos.y = rc.top; size.cx = rc.right - rc.left; // stretch form to full width of screen size.cy = rc.bottom - rc.top; break; case dsScaledCentered: pos = SetPositionCentered(pos, rc, size); break; case dsScaled: case dsFixed: break; } // Create the dialog WindowStyle style; style.hide(); style.control_parent(); form = new WndForm(Parent, pos.x, pos.y, size.cx, size.cy, Caption, style); // Set fore- and background colors Color color; if (StringToColor(node.getAttribute(_T("BackColor")), color)) form->SetBackColor(color); // Load the children controls LoadChildrenFromXML(*form, form->GetClientAreaWindow(), form->GetBackColor(), LookUpTable, &node, dialog_style); // If XML error occurred -> Error messagebox + cancel if (XMLNode::GlobalError) { ShowXMLError(); delete form; return NULL; } // Return the created form return form; }
/** * Displays a MessageBox and returns the pressed button * @param lpText Text displayed inside the MessageBox * @param lpCaption Text displayed in the Caption of the MessageBox * @param uType Type of MessageBox to display (OK+Cancel, Yes+No, etc.) * @return */ int WINAPI MessageBoxX(LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) { WndForm *wf = NULL; WndFrame *wText = NULL; int X, Y, Width, Height; WndButton *wButtons[10]; int ButtonCount = 0; int i, x, y, d, w, h, res, dY; RECT rc; assert(lpText != NULL); assert(lpCaption != NULL); // JMW this makes the first key if pressed quickly, ignored // TODO bug: doesn't work sometimes. buttons have to be pressed multiple times (TB) XCSoarInterface::Debounce(); rc = XCSoarInterface::main_window.get_screen_position(); #ifdef ALTAIRSYNC Width = Layout::Scale(220); Height = Layout::Scale(160); #else Width = Layout::Scale(200); Height = Layout::Scale(160); #endif X = ((rc.right - rc.left) - Width) / 2; Y = ((rc.bottom - rc.top) - Height) / 2; y = Layout::Scale(100); w = Layout::Scale(60); h = Layout::Scale(32); // Create dialog wf = new WndForm(&XCSoarInterface::main_window, _T("frmXcSoarMessageDlg"), lpCaption, X, Y, Width, Height); wf->SetFont(MapWindowBoldFont); wf->SetTitleFont(MapWindowBoldFont); wf->SetBackColor(Color(0xDA, 0xDB, 0xAB)); // Create text element wText = new WndFrame(wf, _T("frmMessageDlgText"), 0, Layout::Scale(5), Width, Height); wText->SetCaption(lpText); wText->SetFont(MapWindowBoldFont); wText->SetCaptionStyle(DT_EXPANDTABS | DT_CENTER | DT_NOCLIP | DT_WORDBREAK); // | DT_VCENTER /* TODO code: this doesnt work to set font height dY = wText->GetLastDrawTextHeight() - Height; */ dY = Layout::Scale(-40); wText->resize(Width, wText->GetTextHeight() + 5); wf->resize(Width, wf->get_size().cy + dY); y += dY; // Create buttons uType = uType & 0x000f; if (uType == MB_OK || uType == MB_OKCANCEL) { wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("OK")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDOK); ButtonCount++; } if (uType == MB_YESNO || uType == MB_YESNOCANCEL) { wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("Yes")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDYES); ButtonCount++; wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("No")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDNO); ButtonCount++; } if (uType == MB_ABORTRETRYIGNORE || uType == MB_RETRYCANCEL) { wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("Retry")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDRETRY); ButtonCount++; } if (uType == MB_OKCANCEL || uType == MB_RETRYCANCEL || uType == MB_YESNOCANCEL) { wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("Cancel")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDCANCEL); ButtonCount++; } if (uType == MB_ABORTRETRYIGNORE) { wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("Abort")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDABORT); ButtonCount++; wButtons[ButtonCount] = new WndButton(wf, _T(""), gettext(_T("Ignore")), 0, y, w, h, OnButtonClick); wButtons[ButtonCount]->SetTag(IDIGNORE); ButtonCount++; } d = Width / (ButtonCount); x = d / 2 - w / 2; // Move buttons to the right positions for (i = 0; i < ButtonCount; i++) { wButtons[i]->move(x, y); x += d; } // Show MessageBox and save result res = wf->ShowModal(); delete wf; #ifdef ALTAIRSYNC // force a refresh of the window behind InvalidateRect(hWnd,NULL,true); UpdateWindow(hWnd); #endif return(res); }